protected static String getSwiftObjectCmd(SwiftClientCfg cfg, String swiftCliPath, String operation,String container, String objectName) { String cmd = getSwiftCmd(cfg,swiftCliPath, operation) +" "+ container+" "+objectName; if(StringUtils.isNotBlank(cfg.getStoragePolicy()) && supportsStoragePolicies(operation)){ return cmd + String.format(WITH_STORAGE_POLICY, cfg.getStoragePolicy()); } return cmd; }
@Test public void testGetSwiftObjectCmd() { SwiftClientCfg cfg = mock(SwiftClientCfg.class); given(cfg.getEndPoint()).willReturn("swift.endpoint"); given(cfg.getAccount()).willReturn("cs"); given(cfg.getUserName()).willReturn("sec-storage"); given(cfg.getKey()).willReturn("mypassword"); given(cfg.getStoragePolicy()).willReturn(null); String objectCmd = SwiftUtil.getSwiftObjectCmd(cfg, "swift", "delete", "T-123", "template.vhd"); String expected = "/usr/bin/python swift -A swift.endpoint -U cs:sec-storage -K mypassword delete T-123 template.vhd"; assertThat(objectCmd, is(equalTo(expected))); }
@Test public void testGetUploadCmd() { SwiftClientCfg cfg = mock(SwiftClientCfg.class); given(cfg.getEndPoint()).willReturn("swift.endpoint"); given(cfg.getAccount()).willReturn("cs"); given(cfg.getUserName()).willReturn("sec-storage"); given(cfg.getKey()).willReturn("mypassword"); given(cfg.getStoragePolicy()).willReturn(null); String uploadCmd = SwiftUtil.getUploadObjectCommand(cfg, "swift", "T-1", "template.vhd", 1024); String expected = "/usr/bin/python swift -A swift.endpoint -U cs:sec-storage -K mypassword upload T-1 template.vhd"; assertThat(uploadCmd, is(equalTo(expected))); }
@Test public void testListContainerCmdWithoutStoragePolicy() { SwiftClientCfg cfg = mock(SwiftClientCfg.class); given(cfg.getEndPoint()).willReturn("swift.endpoint"); given(cfg.getAccount()).willReturn("cs"); given(cfg.getUserName()).willReturn("sec-storage"); given(cfg.getKey()).willReturn("mypassword"); given(cfg.getStoragePolicy()).willReturn(null); String uploadCmd = SwiftUtil.getSwiftContainerCmd(cfg, "swift", "list", "T-1"); String expected = "/usr/bin/python swift -A swift.endpoint -U cs:sec-storage -K mypassword list T-1"; assertThat(uploadCmd, is(equalTo(expected))); } }
@Test public void testListContainerCmdWithStoragePolicyButNotSupportedByOperation() { SwiftClientCfg cfg = mock(SwiftClientCfg.class); given(cfg.getEndPoint()).willReturn("swift.endpoint"); given(cfg.getAccount()).willReturn("cs"); given(cfg.getUserName()).willReturn("sec-storage"); given(cfg.getKey()).willReturn("mypassword"); given(cfg.getStoragePolicy()).willReturn("policy1"); String uploadCmd = SwiftUtil.getSwiftContainerCmd(cfg, "swift", "list", "T-1"); String expected = "/usr/bin/python swift -A swift.endpoint -U cs:sec-storage -K mypassword list T-1"; assertThat(uploadCmd, is(equalTo(expected))); }
@Test public void testGetSwiftContainerCmd() { SwiftClientCfg cfg = mock(SwiftClientCfg.class); given(cfg.getEndPoint()).willReturn("swift.endpoint"); given(cfg.getAccount()).willReturn("cs"); given(cfg.getUserName()).willReturn("sec-storage"); given(cfg.getKey()).willReturn("mypassword"); given(cfg.getStoragePolicy()).willReturn(null); String containerCmd = SwiftUtil.getSwiftContainerCmd(cfg, "swift", "list", "T-123"); String expected = "/usr/bin/python swift -A swift.endpoint -U cs:sec-storage -K mypassword list T-123"; assertThat(containerCmd, is(equalTo(expected))); }
@Test public void testGetSwiftCmd() { SwiftClientCfg cfg = mock(SwiftClientCfg.class); given(cfg.getEndPoint()).willReturn("swift.endpoint"); given(cfg.getAccount()).willReturn("cs"); given(cfg.getUserName()).willReturn("sec-storage"); given(cfg.getKey()).willReturn("mypassword"); given(cfg.getStoragePolicy()).willReturn(null); String cmd = SwiftUtil.getSwiftCmd(cfg, "swift", "stat"); String expected = "/usr/bin/python swift -A swift.endpoint -U cs:sec-storage -K mypassword stat"; assertThat(cmd, is(equalTo(expected))); }
@Test public void testGetUploadCmdWithSegmentsBecauseOfSize() { SwiftClientCfg cfg = mock(SwiftClientCfg.class); given(cfg.getEndPoint()).willReturn("swift.endpoint"); given(cfg.getAccount()).willReturn("cs"); given(cfg.getUserName()).willReturn("sec-storage"); given(cfg.getKey()).willReturn("mypassword"); given(cfg.getStoragePolicy()).willReturn(null); String uploadCmd = SwiftUtil.getUploadObjectCommand(cfg, "swift", "T-1", "template.vhd", 5368709121L); String expected = "/usr/bin/python swift -A swift.endpoint -U cs:sec-storage -K mypassword upload T-1 template.vhd -S 5368709120"; assertThat(uploadCmd, is(equalTo(expected))); }
@Test public void testGetUploadCmdWithSegmentsAndStoragePolicy() { SwiftClientCfg cfg = mock(SwiftClientCfg.class); given(cfg.getEndPoint()).willReturn("swift.endpoint"); given(cfg.getAccount()).willReturn("cs"); given(cfg.getUserName()).willReturn("sec-storage"); given(cfg.getKey()).willReturn("mypassword"); given(cfg.getStoragePolicy()).willReturn("policy1"); String uploadCmd = SwiftUtil.getUploadObjectCommand(cfg, "swift", "T-1", "template.vhd", 5368709121L); String expected = "/usr/bin/python swift -A swift.endpoint -U cs:sec-storage -K mypassword upload T-1 template.vhd --storage-policy \"policy1\" -S 5368709120"; assertThat(uploadCmd, is(equalTo(expected))); }
@Test public void testGetUploadCmdWithStoragePolicy() { SwiftClientCfg cfg = mock(SwiftClientCfg.class); given(cfg.getEndPoint()).willReturn("swift.endpoint"); given(cfg.getAccount()).willReturn("cs"); given(cfg.getUserName()).willReturn("sec-storage"); given(cfg.getKey()).willReturn("mypassword"); given(cfg.getStoragePolicy()).willReturn("policy1"); String uploadCmd = SwiftUtil.getUploadObjectCommand(cfg, "swift", "T-1", "template.vhd", 1024L); String expected = "/usr/bin/python swift -A swift.endpoint -U cs:sec-storage -K mypassword upload T-1 template.vhd --storage-policy \"policy1\""; assertThat(uploadCmd, is(equalTo(expected))); }