def test_create_cloned_volume(self): drv = coho.CohoDriver(configuration=self.configuration) mock_rpc_client = self.mock_object(coho, 'CohoRPCClient') mock_find_share = self.mock_object(drv, '_find_share') mock_find_share.return_value = ADDR + ':' + PATH mock_execute = self.mock_object(drv, '_execute') mock_local_path = self.mock_object(drv, 'local_path') mock_local_path.return_value = LOCAL_PATH mock_get_volume_type = self.mock_object(volume_types, 'get_volume_type') mock_get_volume_type.return_value = VOLUME_TYPE mock_get_qos_specs = self.mock_object(qos_specs, 'get_qos_specs') mock_get_qos_specs.return_value = QOS_SPEC mock_get_admin_context = self.mock_object(context, 'get_admin_context') mock_get_admin_context.return_value = 'test' drv.create_cloned_volume(VOLUME, CLONE_VOL) mock_find_share.assert_has_calls([mock.call(VOLUME)]) mock_local_path.assert_has_calls( [mock.call(VOLUME), mock.call(CLONE_VOL)]) mock_execute.assert_has_calls( [mock.call('cp', LOCAL_PATH, LOCAL_PATH, run_as_root=True)]) self.assertTrue(mock_get_admin_context.called) mock_get_volume_type.assert_has_calls( [mock.call('test', VOLUME_TYPE['id'])]) mock_get_qos_specs.assert_has_calls( [mock.call('test', QOS_SPEC['id'])]) mock_rpc_client.assert_has_calls([ mock.call(ADDR, self.configuration.coho_rpc_port), mock.call().set_qos_policy(os.path.join(PATH, VOLUME['name']), QOS) ])
def test_create_volume_from_snapshot(self): drv = coho.CohoDriver(configuration=self.configuration) mock_rpc_client = self.mock_object(coho, 'CohoRPCClient') mock_find_share = self.mock_object(drv, '_find_share') mock_find_share.return_value = ADDR + ':' + PATH mock_get_volume_type = self.mock_object(volume_types, 'get_volume_type') mock_get_volume_type.return_value = VOLUME_TYPE mock_get_qos_specs = self.mock_object(qos_specs, 'get_qos_specs') mock_get_qos_specs.return_value = QOS_SPEC mock_get_admin_context = self.mock_object(context, 'get_admin_context') mock_get_admin_context.return_value = 'test' drv.create_volume_from_snapshot(VOLUME, SNAPSHOT) mock_find_share.assert_has_calls([mock.call(VOLUME)]) self.assertTrue(mock_get_admin_context.called) mock_get_volume_type.assert_has_calls( [mock.call('test', VOLUME_TYPE['id'])]) mock_get_qos_specs.assert_has_calls( [mock.call('test', QOS_SPEC['id'])]) mock_rpc_client.assert_has_calls([ mock.call(ADDR, self.configuration.coho_rpc_port), mock.call().create_volume_from_snapshot( SNAPSHOT['name'], os.path.join(PATH, VOLUME['name'])), mock.call(ADDR, self.configuration.coho_rpc_port), mock.call().set_qos_policy(os.path.join(PATH, VOLUME['name']), QOS) ])
def test_create_volume_with_qos(self): drv = coho.CohoDriver(configuration=self.configuration) volume = fake_volume.fake_volume_obj( self.context, **{ 'volume_type_id': VOLUME['volume_type_id'], 'provider_location': VOLUME['provider_location'] }) mock_remotefs_create = self.mock_object(remotefs.RemoteFSDriver, 'create_volume') mock_rpc_client = self.mock_object(coho, 'CohoRPCClient') mock_get_volume_type = self.mock_object(volume_types, 'get_volume_type') mock_get_volume_type.return_value = VOLUME_TYPE mock_get_qos_specs = self.mock_object(qos_specs, 'get_qos_specs') mock_get_qos_specs.return_value = QOS_SPEC mock_get_admin_context = self.mock_object(context, 'get_admin_context') mock_get_admin_context.return_value = 'test' drv.create_volume(volume) self.assertTrue(mock_remotefs_create.called) self.assertTrue(mock_get_admin_context.called) mock_remotefs_create.assert_has_calls([mock.call(volume)]) mock_get_volume_type.assert_has_calls( [mock.call('test', volume.volume_type_id)]) mock_get_qos_specs.assert_has_calls( [mock.call('test', QOS_SPEC['id'])]) mock_rpc_client.assert_has_calls([ mock.call(ADDR, self.configuration.coho_rpc_port), mock.call().set_qos_policy(os.path.join(PATH, volume.name), QOS) ])
def test_setup_failure_when_coho_rpc_port_is_invalid(self): self.configuration.coho_rpc_port = 99999 drv = coho.CohoDriver(configuration=self.configuration) self.mock_object(coho, 'LOG') self.mock_object(nfs.NfsDriver, 'do_setup') with self.assertRaisesRegex(exception.CohoException, "Invalid port number.*"): drv.do_setup(self.context) self.assertTrue(coho.LOG.warning.called) self.assertTrue(nfs.NfsDriver.do_setup.called)
def test_setup_failure_when_rpc_port_unconfigured(self): self.configuration.coho_rpc_port = None drv = coho.CohoDriver(configuration=self.configuration) self.mock_object(coho, 'LOG') self.mock_object(nfs.NfsDriver, 'do_setup') with self.assertRaisesRegex(exception.CohoException, ".*Coho rpc port is not configured.*"): drv.do_setup(self.context) self.assertTrue(coho.LOG.warning.called) self.assertTrue(nfs.NfsDriver.do_setup.called)
def test_extend_volume(self): drv = coho.CohoDriver(configuration=self.configuration) mock_execute = self.mock_object(drv, '_execute') mock_local_path = self.mock_object(drv, 'local_path') mock_local_path.return_value = LOCAL_PATH drv.extend_volume(VOLUME, 512) mock_local_path.assert_has_calls([mock.call(VOLUME)]) mock_execute.assert_has_calls([ mock.call('truncate', '-s', '512G', LOCAL_PATH, run_as_root=True) ])
def test_snapshot_failure_when_remote_is_unreachable(self): drv = coho.CohoDriver(configuration=self.configuration) mock_get_volume_location = self.mock_object(coho.CohoDriver, '_get_volume_location') mock_get_volume_location.return_value = 'uknown-address', PATH with self.assertRaisesRegex(exception.CohoException, "Failed to establish connection.*"): drv.create_snapshot(SNAPSHOT) mock_get_volume_location.assert_has_calls( [mock.call(INVALID_SNAPSHOT['volume_id'])])
def test_create_volume_from_snapshot(self): drv = coho.CohoDriver(configuration=self.configuration) mock_rpc_client = self.mock_object(coho, 'CohoRPCClient') mock_find_share = self.mock_object(drv, '_find_share') mock_find_share.return_value = ADDR + ':' + PATH drv.create_volume_from_snapshot(VOLUME, SNAPSHOT) mock_find_share.assert_has_calls( [mock.call(VOLUME['size'])]) mock_rpc_client.assert_has_calls( [mock.call(ADDR, self.configuration.coho_rpc_port), mock.call().create_volume_from_snapshot( SNAPSHOT['name'], os.path.join(PATH, VOLUME['name']))])
def test_delete_snapshot(self): drv = coho.CohoDriver(configuration=self.configuration) mock_rpc_client = self.mock_object(coho, 'CohoRPCClient') mock_get_volume_location = self.mock_object(coho.CohoDriver, '_get_volume_location') mock_get_volume_location.return_value = ADDR, PATH drv.delete_snapshot(SNAPSHOT) mock_get_volume_location.assert_has_calls( [mock.call(SNAPSHOT['volume_id'])]) mock_rpc_client.assert_has_calls( [mock.call(ADDR, self.configuration.coho_rpc_port), mock.call().delete_snapshot(SNAPSHOT['name'])])
def test_create_cloned_volume(self): drv = coho.CohoDriver(configuration=self.configuration) mock_find_share = self.mock_object(drv, '_find_share') mock_find_share.return_value = ADDR + ':' + PATH mock_execute = self.mock_object(drv, '_execute') mock_local_path = self.mock_object(drv, 'local_path') mock_local_path.return_value = LOCAL_PATH drv.create_cloned_volume(VOLUME, CLONE_VOL) mock_find_share.assert_has_calls([mock.call(VOLUME['size'])]) mock_local_path.assert_has_calls( [mock.call(VOLUME), mock.call(CLONE_VOL)]) mock_execute.assert_has_calls( [mock.call('cp', LOCAL_PATH, LOCAL_PATH, run_as_root=True)])
def test_snapshot_failure_with_invalid_input(self): drv = coho.CohoDriver(configuration=self.configuration) self.mock_object(coho.Client, '_make_call') mock_init_socket = self.mock_object(coho.Client, 'init_socket') mock_unpack_uint = self.mock_object(xdrlib.Unpacker, 'unpack_uint') mock_unpack_uint.return_value = errno.EINVAL mock_get_volume_location = self.mock_object(coho.CohoDriver, '_get_volume_location') mock_get_volume_location.return_value = ADDR, PATH with self.assertRaisesRegex(exception.CohoException, "Invalid argument"): drv.delete_snapshot(INVALID_SNAPSHOT) self.assertTrue(mock_init_socket.called) self.assertTrue(mock_unpack_uint.called) mock_get_volume_location.assert_has_calls( [mock.call(INVALID_SNAPSHOT['volume_id'])])
def test_snapshot_failure_when_source_does_not_exist(self): drv = coho.CohoDriver(configuration=self.configuration) self.mock_object(coho.Client, '_make_call') mock_init_socket = self.mock_object(coho.Client, 'init_socket') mock_unpack_uint = self.mock_object(xdrlib.Unpacker, 'unpack_uint') mock_unpack_uint.return_value = errno.ENOENT mock_get_volume_location = self.mock_object(coho.CohoDriver, '_get_volume_location') mock_get_volume_location.return_value = ADDR, PATH with self.assertRaisesRegex(exception.CohoException, "No such file or directory.*"): drv.create_snapshot(SNAPSHOT) self.assertTrue(mock_init_socket.called) self.assertTrue(mock_unpack_uint.called) mock_get_volume_location.assert_has_calls( [mock.call(SNAPSHOT['volume_id'])])
def test_retype(self): drv = coho.CohoDriver(configuration=self.configuration) mock_rpc_client = self.mock_object(coho, 'CohoRPCClient') mock_get_volume_type = self.mock_object(volume_types, 'get_volume_type') mock_get_volume_type.return_value = VOLUME_TYPE mock_get_qos_specs = self.mock_object(qos_specs, 'get_qos_specs') mock_get_qos_specs.return_value = QOS_SPEC drv.retype('test', VOLUME, VOLUME_TYPE, None, None) mock_get_volume_type.assert_has_calls( [mock.call('test', VOLUME_TYPE['id'])]) mock_get_qos_specs.assert_has_calls( [mock.call('test', QOS_SPEC['id'])]) mock_rpc_client.assert_has_calls([ mock.call(ADDR, self.configuration.coho_rpc_port), mock.call().set_qos_policy(os.path.join(PATH, VOLUME['name']), QOS) ])