示例#1
0
    def test_create_volume_from_snapshot(self, mock_run_cmd):
        self.driver.create_volume_from_snapshot(VOLUME, SNAPSHOT)

        expected_cmd = rdx_cli_api.RdxApiCmd("volumes clone",
                                             argument=SRC_VOL_RDX_NAME,
                                             flags={
                                                 "name": VOLUME_RDX_NAME,
                                                 "bookmark": SNAPSHOT_RDX_NAME,
                                                 "description": VOLUME_RDX_DESC
                                             })

        mock_run_cmd.assert_called_with(expected_cmd)

        # Test resize
        bigger_vol = copy.deepcopy(VOLUME)
        bigger_size = SNAPSHOT['volume_size'] + 10
        bigger_vol['size'] = bigger_size

        self.driver.create_volume_from_snapshot(bigger_vol, SNAPSHOT)

        expected_cmd = rdx_cli_api.RdxApiCmd("volumes update",
                                             argument=VOLUME_RDX_NAME,
                                             flags={"size": bigger_size})

        mock_run_cmd.assert_called_with(expected_cmd)
示例#2
0
    def test_create_snapshot(self, mock_run_cmd):
        self.driver.create_snapshot(SNAPSHOT)

        expected_cmd = rdx_cli_api.RdxApiCmd("volumes bookmark",
                                             argument=SRC_VOL_RDX_NAME,
                                             flags={
                                                 "name": SNAPSHOT_RDX_NAME,
                                                 "type": "manual"
                                             })

        mock_run_cmd.assert_called_with(expected_cmd)

        backdated_snap = copy.deepcopy(SNAPSHOT)
        clone_date = "02/17/2015-11:39:00"
        backdated_snap["metadata"]["backdate"] = clone_date

        self.driver.create_snapshot(backdated_snap)

        expected_cmd = rdx_cli_api.RdxApiCmd("volumes bookmark",
                                             argument=SRC_VOL_RDX_NAME,
                                             flags={
                                                 "name": SNAPSHOT_RDX_NAME,
                                                 "type": "manual",
                                                 "timestamp": clone_date
                                             })

        mock_run_cmd.assert_called_with(expected_cmd)
示例#3
0
 def test_create_volume(self, mock_run_cmd):
     self.driver.create_volume(VOLUME)
     expected_cmd = rdx_cli_api.RdxApiCmd(
         "volumes new",
         argument=VOLUME_RDX_NAME,
         flags=[["size", VOLUME["size"]], ["description", VOLUME_RDX_DESC]])
     mock_run_cmd.assert_called_with(expected_cmd)
示例#4
0
    def test_delete_snapshot(self, mock_run_cmd):
        self.driver.delete_snapshot(SNAPSHOT)

        expected_cmd = rdx_cli_api.RdxApiCmd("volumes delete-bookmark",
                                             argument=SRC_VOL_RDX_NAME,
                                             flags={"name": SNAPSHOT_RDX_NAME})

        mock_run_cmd.assert_called_with(expected_cmd)
示例#5
0
    def test_extend_volume(self, mock_run_cmd):
        new_size = VOLUME["size"] + 1
        self.driver.extend_volume(VOLUME, new_size)

        expected_cmd = rdx_cli_api.RdxApiCmd("volumes update",
                                             argument=VOLUME_RDX_NAME,
                                             flags={"size": new_size})

        mock_run_cmd.assert_called_with(expected_cmd)
示例#6
0
    def test_unmanage(self, mock_run_cmd):
        source_name = 'test-source'
        self.driver.rdxApi.find_volume_by_name = mock.Mock()
        self.driver.rdxApi.find_volume_by_name.return_value = {
            'name': source_name,
            'description': "openstack_1234"
        }
        self.driver.unmanage(VOLUME)

        expected_cmd = rdx_cli_api.RdxApiCmd("volumes update",
                                             argument=VOLUME_RDX_NAME,
                                             flags=[["description", ""]])
        mock_run_cmd.assert_called_with(expected_cmd)
示例#7
0
    def test_terminate_connection(self, mock_run_cmd):
        generated_host_name = "openstack-123456789012"
        self.driver.rdxApi.list_hosts = mock.Mock()
        self.driver.rdxApi.list_hosts.return_value = [{
            "iscsi_name":
            CONNECTOR["initiator"],
            "name":
            generated_host_name
        }]

        self.driver.terminate_connection(VOLUME, CONNECTOR)

        unassign_cmd = rdx_cli_api.RdxApiCmd(
            "volumes unassign",
            argument=VOLUME_RDX_NAME,
            flags={"host": generated_host_name})

        mock_run_cmd.assert_has_calls(
            [mock.call.driver._run_cmd(unassign_cmd)])
示例#8
0
    def test_create_cloned_volume(self, mock_run_cmd):
        self.driver.create_cloned_volume(VOLUME, SRC_VOL)

        expected_cmd = rdx_cli_api.RdxApiCmd("volumes clone",
                                             argument=SRC_VOL_RDX_NAME,
                                             flags={
                                                 "name": VOLUME_RDX_NAME,
                                                 "description": VOLUME_RDX_DESC
                                             })

        mock_run_cmd.assert_called_with(expected_cmd)

        # Test clone from date
        backdated_clone = copy.deepcopy(VOLUME)
        clone_date = "02/17/2015-11:39:00"
        backdated_clone["metadata"]["backdate"] = clone_date

        self.driver.create_cloned_volume(backdated_clone, SRC_VOL)
        expected_cmd.add_flag("timestamp", clone_date)
        mock_run_cmd.assert_called_with(expected_cmd)
示例#9
0
    def test_manage_existing(self, mock_run_cmd):
        source_name = 'test-source'
        self.driver.rdxApi.find_volume_by_name = mock.Mock()
        self.driver.rdxApi.find_volume_by_name.return_value = {
            'name': source_name,
            'description': None
        }
        self.driver.manage_existing(VOLUME, {'source-name': source_name})

        expected_cmd = rdx_cli_api.RdxApiCmd(
            "volumes update",
            argument=source_name,
            flags=[["new-name", VOLUME_RDX_NAME],
                   ["description", VOLUME_RDX_DESC]])
        mock_run_cmd.assert_called_with(expected_cmd)

        self.driver.rdxApi.find_volume_by_name.return_value = {
            'name': source_name,
            'description': "openstack_1234"
        }

        self.assertRaises(exception.ManageExistingAlreadyManaged,
                          self.driver.manage_existing, VOLUME,
                          {'source-name': source_name})
示例#10
0
    def test_initialize_connection(self, mock_list_assignmnet, mock_run_cmd):
        generated_host_name = "openstack-123456789012"
        self.driver.rdxApi.list_hosts = mock.Mock()
        self.driver.rdxApi.list_hosts.return_value = []
        self.driver._generate_initiator_name = mock.Mock()
        self.driver._generate_initiator_name.return_value = generated_host_name

        ret_connection_info = self.driver.initialize_connection(
            VOLUME, CONNECTOR)

        create_host_cmd = rdx_cli_api.RdxApiCmd(
            "hosts new",
            argument=generated_host_name,
            flags={"iscsi-name": CONNECTOR["initiator"]})
        assign_cmd = rdx_cli_api.RdxApiCmd("volumes assign",
                                           argument=VOLUME_RDX_NAME,
                                           flags={"host": generated_host_name})

        calls = [
            mock.call.driver._run_cmd(create_host_cmd),
            mock.call.driver._run_cmd(assign_cmd)
        ]

        mock_run_cmd.assert_has_calls(calls)
        self.assertDictMatch(ret_connection_info,
                             ISCSI_CONNECTION_INFO_NO_MULTIPATH)

        connector = copy.deepcopy(CONNECTOR)
        connector["multipath"] = True

        ret_connection_info = self.driver.initialize_connection(
            VOLUME, connector)

        create_host_cmd = rdx_cli_api.RdxApiCmd(
            "hosts new",
            argument=generated_host_name,
            flags={"iscsi-name": CONNECTOR["initiator"]})

        assign_cmd = rdx_cli_api.RdxApiCmd("volumes assign",
                                           argument=VOLUME_RDX_NAME,
                                           flags={"host": generated_host_name})

        calls = [
            mock.call.driver._run_cmd(create_host_cmd),
            mock.call.driver._run_cmd(assign_cmd)
        ]

        mock_run_cmd.assert_has_calls(calls)
        self.assertDictMatch(ret_connection_info, ISCSI_CONNECTION_INFO)

        self.driver.rdxApi.list_hosts.return_value = [{
            "iscsi_name":
            CONNECTOR["initiator"],
            "name":
            generated_host_name
        }]

        ret_connection_info = self.driver.initialize_connection(
            VOLUME, connector)

        mock_run_cmd.assert_has_calls([mock.call.driver._run_cmd(assign_cmd)])

        self.assertDictMatch(ISCSI_CONNECTION_INFO, ret_connection_info)
示例#11
0
 def test_delete_volume(self, mock_run_cmd):
     self.driver.delete_volume(VOLUME)
     expected_cmd = rdx_cli_api.RdxApiCmd(
         "volumes delete {} -force".format(VOLUME_RDX_NAME))
     mock_run_cmd.assert_called_with(expected_cmd)