def test_get_all_by_host_and_share_net_valid(self): valid = { 'share_network_id': '1', 'host': 'host1', 'status': constants.STATUS_ACTIVE, } invalid = { 'share_network_id': '1', 'host': 'host1', 'status': constants.STATUS_ERROR, } other = { 'share_network_id': '2', 'host': 'host2', 'status': constants.STATUS_ACTIVE, } valid = db_utils.create_share_server(**valid) db_utils.create_share_server(**invalid) db_utils.create_share_server(**other) servers = db_api.share_server_get_all_by_host_and_share_net_valid( self.ctxt, host='host1', share_net_id='1') self.assertEqual(servers[0]['id'], valid['id'])
def test_get_all(self): srv1 = { 'share_network_id': '1', 'host': 'host1', 'status': constants.STATUS_ACTIVE, } srv2 = { 'share_network_id': '1', 'host': 'host1', 'status': constants.STATUS_ERROR, } srv3 = { 'share_network_id': '2', 'host': 'host2', 'status': constants.STATUS_ACTIVE, } servers = db_api.share_server_get_all(self.ctxt) self.assertEqual(len(servers), 0) to_delete = db_utils.create_share_server(**srv1) db_utils.create_share_server(**srv2) db_utils.create_share_server(**srv3) servers = db_api.share_server_get_all(self.ctxt) self.assertEqual(len(servers), 3) db_api.share_server_delete(self.ctxt, to_delete['id']) servers = db_api.share_server_get_all(self.ctxt) self.assertEqual(len(servers), 2)
def setUp(self): super(ShareRpcAPITestCase, self).setUp() self.context = context.get_admin_context() share = db_utils.create_share( availability_zone=CONF.storage_availability_zone, status=constants.STATUS_AVAILABLE) snapshot = db_utils.create_snapshot(share_id=share['id']) share_replica = db_utils.create_share_replica( id='fake_replica', share_id='fake_share_id', host='fake_host', ) share_server = db_utils.create_share_server() share_group = {'id': 'fake_share_group_id', 'host': 'fake_host'} share_group_snapshot = {'id': 'fake_share_group_id'} host = 'fake_host' self.fake_share = jsonutils.to_primitive(share) # mock out the getattr on the share db model object since jsonutils # doesn't know about those extra attributes to pull in self.fake_share['instance'] = jsonutils.to_primitive(share.instance) self.fake_share_replica = jsonutils.to_primitive(share_replica) self.fake_snapshot = jsonutils.to_primitive(snapshot) self.fake_snapshot['share_instance'] = jsonutils.to_primitive( snapshot.instance) self.fake_share_server = jsonutils.to_primitive(share_server) self.fake_share_group = jsonutils.to_primitive(share_group) self.fake_share_group_snapshot = jsonutils.to_primitive( share_group_snapshot) self.fake_host = jsonutils.to_primitive(host) self.ctxt = context.RequestContext('fake_user', 'fake_project') self.rpcapi = share_rpcapi.ShareAPI()
def test_share_server_migration_start_conflict(self, api_exception, expected_exception): server = db_utils.create_share_server(id='fake_server_id', status=constants.STATUS_ACTIVE) req = self._get_server_migration_request(server['id']) context = req.environ['manila.context'] body = { 'migration_start': { 'host': 'fake_host', 'preserve_snapshots': True, 'writable': True, 'nondisruptive': True, } } self.mock_object(share_api.API, 'share_server_migration_start', mock.Mock(side_effect=api_exception)) self.mock_object(db_api, 'share_server_get', mock.Mock(return_value=server)) self.assertRaises(expected_exception, self.controller.share_server_migration_start, req, server['id'], body) db_api.share_server_get.assert_called_once_with(context, server['id']) migration_start_params = body['migration_start'] share_api.API.share_server_migration_start.assert_called_once_with( context, server, migration_start_params['host'], migration_start_params['writable'], migration_start_params['nondisruptive'], migration_start_params['preserve_snapshots'], new_share_network=None)
def test_share_server_migration_start_new_share_network_not_found(self): server = db_utils.create_share_server( id='fake_server_id', status=constants.STATUS_ACTIVE) req = self._get_server_migration_request(server['id']) context = req.environ['manila.context'] body = { 'migration_start': { 'host': 'fake_host', 'preserve_metadata': True, 'preserve_snapshots': True, 'writable': True, 'nondisruptive': True, 'new_share_network_id': 'nonexistent'}} self.mock_object(db_api, 'share_network_get', mock.Mock(side_effect=exception.NotFound())) self.mock_object(db_api, 'share_server_get', mock.Mock(return_value=server)) self.assertRaises(webob.exc.HTTPBadRequest, self.controller.share_server_migration_start, req, server['id'], body) db_api.share_network_get.assert_called_once_with(context, 'nonexistent') db_api.share_server_get.assert_called_once_with(context, server['id'])
def test_share_server_migration_start_non_boolean(self, param): server = db_utils.create_share_server( id='fake_server_id', status=constants.STATUS_ACTIVE) req = self._get_server_migration_request(server['id']) context = req.environ['manila.context'] body = { 'migration_start': { 'host': 'fake_host', 'preserve_snapshots': True, 'writable': True, 'nondisruptive': True, } } body['migration_start'][param] = None method = 'share_server_migration_start' self.mock_object(share_api.API, method) self.mock_object(db_api, 'share_server_get', mock.Mock(return_value=server)) self.assertRaises(webob.exc.HTTPBadRequest, getattr(self.controller, method), req, server['id'], body) db_api.share_server_get.assert_called_once_with(context, server['id'])
def setUp(self): super(ShareRpcAPITestCase, self).setUp() self.context = context.get_admin_context() share = db_utils.create_share( availability_zone=CONF.storage_availability_zone, status=constants.STATUS_AVAILABLE ) access = db_utils.create_access(share_id=share['id']) snapshot = db_utils.create_snapshot(share_id=share['id']) share_replica = db_utils.create_share_replica( id='fake_replica', share_id='fake_share_id', host='fake_host', ) share_server = db_utils.create_share_server() cg = {'id': 'fake_cg_id', 'host': 'fake_host'} cgsnapshot = {'id': 'fake_cg_id'} host = {'host': 'fake_host', 'capabilities': 1} self.fake_share = jsonutils.to_primitive(share) # mock out the getattr on the share db model object since jsonutils # doesn't know about those extra attributes to pull in self.fake_share['instance'] = jsonutils.to_primitive(share.instance) self.fake_share_replica = jsonutils.to_primitive(share_replica) self.fake_access = jsonutils.to_primitive(access) self.fake_snapshot = jsonutils.to_primitive(snapshot) self.fake_share_server = jsonutils.to_primitive(share_server) self.fake_cg = jsonutils.to_primitive(cg) self.fake_cgsnapshot = jsonutils.to_primitive(cgsnapshot) self.fake_host = jsonutils.to_primitive(host) self.ctxt = context.RequestContext('fake_user', 'fake_project') self.rpcapi = share_rpcapi.ShareAPI()
def test_update_share_server_security_service_not_supported(self): new_security_service = db_utils.create_security_service() current_security_service = db_utils.create_security_service() share_server = db_utils.create_share_server() share_instances = [] share_instance_access_rules = [] network_info = {} mock_check_update = self.mock_object( self._driver, 'check_update_share_server_security_service', mock.Mock(return_value=False)) self.assertRaises(exception.ManilaException, self._driver.update_share_server_security_service, self._context, share_server, network_info, share_instances, share_instance_access_rules, new_security_service, current_security_service=current_security_service) mock_check_update.assert_called_once_with( self._context, share_server, network_info, share_instances, share_instance_access_rules, new_security_service, current_security_service=current_security_service)
def test_revert_access_rules(self): share_instance = db_utils.create_share_instance( share_id=self.share['id'], status=constants.STATUS_AVAILABLE) access = db_utils.create_access(share_id=self.share['id'], access_to='fake_ip', access_level='rw') server = db_utils.create_share_server(share_id=self.share['id']) # mocks self.mock_object(self.access_helper, 'update_access_rules') get_and_update_call = self.mock_object( self.access_helper, 'get_and_update_share_instance_access_rules', mock.Mock(return_value=[access])) # run self.helper.revert_access_rules(share_instance, server) # asserts get_and_update_call.assert_called_once_with( self.context, share_instance_id=share_instance['id'], updates={'state': constants.ACCESS_STATE_QUEUED_TO_APPLY}) self.access_helper.update_access_rules.assert_called_once_with( self.context, share_instance['id'], share_server=server)
def test_revert_access_rules(self): share_instance = db_utils.create_share_instance( share_id=self.share['id'], status=constants.STATUS_AVAILABLE) access = db_utils.create_access(share_id=self.share['id'], access_to='fake_ip', access_level='rw') server = db_utils.create_share_server(share_id=self.share['id']) # mocks share_driver = mock.Mock() self.mock_object(share_driver, 'update_access') self.mock_object(db, 'share_access_get_all_for_instance', mock.Mock(return_value=[access])) # run self.helper.revert_access_rules(share_instance, server, share_driver) # asserts db.share_access_get_all_for_instance.assert_called_once_with( self.context, share_instance['id']) share_driver.update_access.assert_called_once_with( self.context, share_instance, [access], add_rules=[], delete_rules=[], share_server=server)
def setUp(self): super(ShareRpcAPITestCase, self).setUp() self.context = context.get_admin_context() share = db_utils.create_share( availability_zone=CONF.storage_availability_zone, status=constants.STATUS_AVAILABLE) access = db_utils.create_access(share_id=share['id']) snapshot = db_utils.create_snapshot(share_id=share['id']) share_replica = db_utils.create_share_replica( id='fake_replica', share_id='fake_share_id', ) share_server = db_utils.create_share_server() cg = {'id': 'fake_cg_id', 'host': 'fake_host'} cgsnapshot = {'id': 'fake_cg_id'} host = {'host': 'fake_host', 'capabilities': 1} self.fake_share = jsonutils.to_primitive(share) self.fake_share_replica = jsonutils.to_primitive(share_replica) self.fake_access = jsonutils.to_primitive(access) self.fake_snapshot = jsonutils.to_primitive(snapshot) self.fake_share_server = jsonutils.to_primitive(share_server) self.fake_cg = jsonutils.to_primitive(cg) self.fake_cgsnapshot = jsonutils.to_primitive(cgsnapshot) self.fake_host = jsonutils.to_primitive(host) self.ctxt = context.RequestContext('fake_user', 'fake_project') self.rpcapi = share_rpcapi.ShareAPI()
def test_revert_access_rules(self): share_instance = db_utils.create_share_instance( share_id=self.share['id'], status=constants.STATUS_AVAILABLE) access = db_utils.create_access(share_id=self.share['id'], access_to='fake_ip', access_level='rw') server = db_utils.create_share_server(share_id=self.share['id']) # mocks share_driver = mock.Mock() self.mock_object(share_driver, 'update_access') self.mock_object(db, 'share_access_get_all_for_instance', mock.Mock(return_value=[access])) # run self.helper.revert_access_rules(share_instance, server, share_driver) # asserts db.share_access_get_all_for_instance.assert_called_once_with( self.context, share_instance['id']) share_driver.update_access.assert_called_once_with(self.context, share_instance, [access], add_rules=[], delete_rules=[], share_server=server)
def test_unmanage_share_server_network_not_active(self): """Tests unmanaging share servers""" req = fakes.HTTPRequest.blank( '/v2/share-servers/fake_server_id/', version="2.63") context = req.environ['manila.context'] share_server = db_utils.create_share_server() network_subnet = db_utils.create_share_network_subnet() share_network = db_utils.create_share_network() get_mock = self.mock_object( db_api, 'share_server_get', mock.Mock(return_value=share_server)) get_subnet_mock = self.mock_object( db_api, 'share_network_subnet_get', mock.Mock(return_value=network_subnet)) get_network_mock = self.mock_object( db_api, 'share_network_get', mock.Mock(return_value=share_network)) is_active_mock = self.mock_object( common, 'check_share_network_is_active', mock.Mock(side_effect=webob.exc.HTTPBadRequest())) body = {'unmanage': {'force': True}} self.assertRaises(webob.exc.HTTPBadRequest, self.controller.unmanage, req, 'fake_server_id', body) get_mock.assert_called_once_with(context, 'fake_server_id') get_subnet_mock.assert_called_once_with( context, share_server.get('share_network_subnet_id')) get_network_mock.assert_called_once_with( context, network_subnet['share_network_id']) is_active_mock.assert_called_once_with(share_network)
def test_share_server_get(self): expected = db_utils.create_share_server() server = db_api.share_server_get(self.ctxt, expected['id']) self.assertEqual(expected['id'], server['id']) self.assertEqual(server.share_network_id, expected.share_network_id) self.assertEqual(server.host, expected.host) self.assertEqual(server.status, expected.status)
def test_share_server_migration_check(self): fake_id = 'fake_server_id' fake_share_server = db_utils.create_share_server(id=fake_id) fake_share_network = db_utils.create_share_network() req = self._get_server_migration_request(fake_id) context = req.environ['manila.context'] requested_writable = False requested_nondisruptive = False requested_preserve_snapshots = False fake_host = 'fakehost@fakebackend' body = { 'migration_check': { 'writable': requested_writable, 'nondisruptive': requested_nondisruptive, 'preserve_snapshots': requested_preserve_snapshots, 'new_share_network_id': fake_share_network['id'], 'host': fake_host } } driver_result = { 'compatible': False, 'writable': False, 'nondisruptive': True, 'preserve_snapshots': False, 'share_network_id': 'fake_network_uuid', 'migration_cancel': False, 'migration_get_progress': False, } mock_server_get = self.mock_object( db_api, 'share_server_get', mock.Mock(return_value=fake_share_server)) mock_network_get = self.mock_object( db_api, 'share_network_get', mock.Mock(return_value=fake_share_network)) mock_migration_check = self.mock_object( share_api.API, 'share_server_migration_check', mock.Mock(return_value=driver_result)) result = self.controller.share_server_migration_check( req, fake_id, body) expected_result_keys = [ 'compatible', 'requested_capabilities', 'supported_capabilities' ] [self.assertIn(key, result) for key in expected_result_keys] mock_server_get.assert_called_once_with(context, fake_share_server['id']) mock_network_get.assert_called_once_with(context, fake_share_network['id']) mock_migration_check.assert_called_once_with( context, fake_share_server, fake_host, requested_writable, requested_nondisruptive, requested_preserve_snapshots, new_share_network=fake_share_network)
def test_manage(self, share_net_name): """Tests share server manage""" req = fakes.HTTPRequest.blank('/v2/share-servers/', use_admin_context=True, version="2.49") context = req.environ['manila.context'] share_network = db_utils.create_share_network(name=share_net_name) share_server = db_utils.create_share_server( share_network_id=share_network['id'], host='fake_host', identifier='fake_identifier', is_auto_deletable=False) self.mock_object(db_api, 'share_network_get', mock.Mock( return_value=share_network)) self.mock_object(utils, 'validate_service_host') body = { 'share_server': self._setup_manage_test_request_body() } manage_share_server_mock = self.mock_object( share_api.API, 'manage_share_server', mock.Mock(return_value=share_server)) result = self.controller.manage(req, body) expected_result = { 'share_server': { 'id': share_server['id'], 'project_id': 'fake', 'updated_at': None, 'status': constants.STATUS_ACTIVE, 'host': 'fake_host', 'share_network_id': share_server['share_network_id'], 'created_at': share_server['created_at'], 'backend_details': {}, 'identifier': share_server['identifier'], 'is_auto_deletable': share_server['is_auto_deletable'], } } if share_net_name != '': expected_result['share_server']['share_network_name'] = ( 'fake_net_name') else: expected_result['share_server']['share_network_name'] = ( share_server['share_network_id']) req_params = body['share_server'] manage_share_server_mock.assert_called_once_with( context, req_params['identifier'], req_params['host'], share_network, req_params['driver_options']) self.assertEqual(expected_result, result) self.mock_policy_check.assert_called_once_with( context, self.resource_name, 'manage_share_server')
def test_delete_with_details(self): server = db_utils.create_share_server(backend_details={ 'value1': '1', 'value2': '2', }) num_records = len(db_api.share_server_get_all(self.ctxt)) db_api.share_server_delete(self.ctxt, server['id']) self.assertEqual(len(db_api.share_server_get_all(self.ctxt)), num_records - 1)
def test_manage(self, share_net_name): """Tests share server manage""" req = fakes.HTTPRequest.blank('/v2/share-servers/', use_admin_context=True, version="2.49") context = req.environ['manila.context'] share_network = db_utils.create_share_network(name=share_net_name) share_server = db_utils.create_share_server( share_network_id=share_network['id'], host='fake_host', identifier='fake_identifier', is_auto_deletable=False) self.mock_object(db_api, 'share_network_get', mock.Mock(return_value=share_network)) self.mock_object(utils, 'validate_service_host') body = {'share_server': self._setup_manage_test_request_body()} manage_share_server_mock = self.mock_object( share_api.API, 'manage_share_server', mock.Mock(return_value=share_server)) result = self.controller.manage(req, body) expected_result = { 'share_server': { 'id': share_server['id'], 'project_id': 'fake', 'updated_at': None, 'status': constants.STATUS_ACTIVE, 'host': 'fake_host', 'share_network_id': share_server['share_network_id'], 'created_at': share_server['created_at'], 'backend_details': {}, 'identifier': share_server['identifier'], 'is_auto_deletable': share_server['is_auto_deletable'], } } if share_net_name != '': expected_result['share_server']['share_network_name'] = ( 'fake_net_name') else: expected_result['share_server']['share_network_name'] = ( share_server['share_network_id']) req_params = body['share_server'] manage_share_server_mock.assert_called_once_with( context, req_params['identifier'], req_params['host'], share_network, req_params['driver_options']) self.assertEqual(expected_result, result) self.mock_policy_check.assert_called_once_with(context, self.resource_name, 'manage_share_server')
def test_reset_task_state_error_invalid(self): server = db_utils.create_share_server( id='fake_server_id', status=constants.STATUS_ACTIVE) req = self._get_server_migration_request(server['id']) update = {'task_state': 'error'} body = {'reset_task_state': update} self.assertRaises(webob.exc.HTTPBadRequest, self.controller.share_server_reset_task_state, req, server['id'], body)
def test_share_filter_all_by_share_server(self): share_network = db_utils.create_share_network() share_server = db_utils.create_share_server( share_network_id=share_network['id']) share = db_utils.create_share(share_server_id=share_server['id'], share_network_id=share_network['id']) actual_result = db_api.share_get_all_by_share_server( self.ctxt, share_server['id']) self.assertEqual(1, len(actual_result)) self.assertEqual(share['id'], actual_result[0].id)
def test_setup_security_service(self): share_server = db_utils.create_share_server() security_service = db_utils.create_security_service() mock_ldap_bind = self.mock_object(self.security_service_helper, 'ldap_bind') self.security_service_helper.setup_security_service( share_server['id'], security_service) mock_ldap_bind.assert_called_once_with(share_server['id'], security_service)
def test_backend_details_set(self): details = { 'value1': '1', 'value2': '2', } server = db_utils.create_share_server() db_api.share_server_backend_details_set(self.ctxt, server['id'], details) self.assertDictMatch( details, db_api.share_server_get(self.ctxt, server['id'])['backend_details'] )
def _setup_unmanage_tests(self, status=constants.STATUS_ACTIVE): server = db_utils.create_share_server( id='fake_server_id', status=status) share_network = db_utils.create_share_network() network_subnet = db_utils.create_share_network_subnet( share_network_id=share_network['id']) self.mock_object(db_api, 'share_server_get', mock.Mock(return_value=server)) self.mock_object(db_api, 'share_network_get', mock.Mock(return_value=share_network)) self.mock_object(db_api, 'share_network_subnet_get', mock.Mock(return_value=network_subnet)) return server
def test_update(self): update = { 'share_network_id': 'update_net', 'host': 'update_host', 'status': constants.STATUS_ACTIVE, } server = db_utils.create_share_server() updated_server = db_api.share_server_update(self.ctxt, server['id'], update) self.assertEqual(server['id'], updated_server['id']) self.assertEqual(updated_server.share_network_id, update['share_network_id']) self.assertEqual(updated_server.host, update['host']) self.assertEqual(updated_server.status, update['status'])
def setUp(self): super(ShareNetworkSubnetControllerTest, self).setUp() self.controller = share_network_subnets.ShareNetworkSubnetController() self.mock_policy_check = self.mock_object( policy, 'check_policy', mock.Mock(return_value=True)) self.resource_name = self.controller.resource_name self.mock_az_get = self.mock_object(db_api, 'availability_zone_get', mock.Mock(return_value=fake_az)) self.share_network = db_utils.create_share_network( name='fake_network', id='fake_sn_id') self.share_server = db_utils.create_share_server( share_network_subnet_id='fake_sns_id') self.subnet = db_utils.create_share_network_subnet( share_network_id=self.share_network['id']) self.share = db_utils.create_share()
def setUp(self): super(ShareRpcAPITestCase, self).setUp() self.context = context.get_admin_context() share = db_utils.create_share( availability_zone=CONF.storage_availability_zone, status=constants.STATUS_AVAILABLE ) access = db_utils.create_access(share_id=share['id']) snapshot = db_utils.create_snapshot(share_id=share['id']) share_server = db_utils.create_share_server() self.fake_share = jsonutils.to_primitive(share) self.fake_access = jsonutils.to_primitive(access) self.fake_snapshot = jsonutils.to_primitive(snapshot) self.fake_share_server = jsonutils.to_primitive(share_server) self.ctxt = context.RequestContext('fake_user', 'fake_project') self.rpcapi = share_rpcapi.ShareAPI()
def test_reset_task_state(self, task_state): server = db_utils.create_share_server( id='fake_server_id', status=constants.STATUS_ACTIVE) req = self._get_server_migration_request(server['id']) update = {'task_state': task_state} body = {'reset_task_state': update} self.mock_object(db_api, 'share_server_update') response = self.controller.share_server_reset_task_state( req, server['id'], body) self.assertEqual(202, response.status_int) db_api.share_server_update.assert_called_once_with(utils.IsAMatcher( ctx_api.RequestContext), server['id'], update)
def test_share_server_migration_cancel(self): server = db_utils.create_share_server(id='fake_server_id', status=constants.STATUS_ACTIVE) req = self._get_server_migration_request(server['id']) context = req.environ['manila.context'] body = {'migration_cancel': None} self.mock_object(db_api, 'share_server_get', mock.Mock(return_value=server)) self.mock_object(share_api.API, 'share_server_migration_cancel') self.controller.share_server_migration_cancel(req, server['id'], body) share_api.API.share_server_migration_cancel.assert_called_once_with( utils.IsAMatcher(ctx_api.RequestContext), server) db_api.share_server_get.assert_called_once_with(context, server['id'])
def test_update_share_server_security_service(self, with_current_service): new_security_service = db_utils.create_security_service() current_security_service = (db_utils.create_security_service() if with_current_service else None) share_server = db_utils.create_share_server() fake_container_name = 'fake_name' network_info = {} share_instances = [] share_instance_access_rules = [] mock_check_update = self.mock_object( self._driver, 'check_update_share_server_security_service', mock.Mock(return_value=True)) mock_get_container_name = self.mock_object( self._driver, '_get_container_name', mock.Mock(return_value=fake_container_name)) mock_setup = self.mock_object(self._driver, 'setup_security_services') mock_update_sec_service = self.mock_object( self._driver.security_service_helper, 'update_security_service') self._driver.update_share_server_security_service( self._context, share_server, network_info, share_instances, share_instance_access_rules, new_security_service, current_security_service=current_security_service) mock_check_update.assert_called_once_with( self._context, share_server, network_info, share_instances, share_instance_access_rules, new_security_service, current_security_service=current_security_service) mock_get_container_name.assert_called_once_with(share_server['id']) if with_current_service: mock_update_sec_service.assert_called_once_with( fake_container_name, current_security_service, new_security_service) else: mock_setup.assert_called_once_with(fake_container_name, [new_security_service])
def test_share_server_migration_check_host_with_pool(self): server = db_utils.create_share_server(id='fake_server_id', status=constants.STATUS_ACTIVE) req = self._get_server_migration_request(server['id']) body = { 'migration_start': { 'host': 'fake_host@fakebackend#pool', 'preserve_snapshots': True, 'writable': True, 'nondisruptive': True, 'new_share_network_id': 'fake_net_id', } } self.assertRaises(webob.exc.HTTPBadRequest, self.controller.share_server_migration_check, req, server['id'], body)
def test_reset_task_state_not_found(self): server = db_utils.create_share_server( id='fake_server_id', status=constants.STATUS_ACTIVE) req = self._get_server_migration_request(server['id']) update = {'task_state': constants.TASK_STATE_MIGRATION_ERROR} body = {'reset_task_state': update} self.mock_object(db_api, 'share_server_update', mock.Mock(side_effect=exception.ShareServerNotFound( share_server_id='fake_server_id'))) self.assertRaises(webob.exc.HTTPNotFound, self.controller.share_server_reset_task_state, req, server['id'], body) db_api.share_server_update.assert_called_once_with(utils.IsAMatcher( ctx_api.RequestContext), server['id'], update)
def test_cleanup_access_rules(self, exc): # mocks server = db_utils.create_share_server() self.mock_object(self.helper, 'revert_access_rules', mock.Mock(side_effect=exc)) self.mock_object(migration.LOG, 'warning') # run self.helper.cleanup_access_rules(self.share_instance, server) # asserts self.helper.revert_access_rules.assert_called_once_with( self.share_instance, server) if exc: self.assertEqual(1, migration.LOG.warning.call_count)
def test_get_with_details(self): values = { 'share_network_id': 'fake-share-net-id', 'host': 'hostname', 'status': constants.STATUS_ACTIVE, } details = { 'value1': '1', 'value2': '2', } srv_id = db_utils.create_share_server(**values)['id'] db_api.share_server_backend_details_set(self.ctxt, srv_id, details) server = db_api.share_server_get(self.ctxt, srv_id) self.assertEqual(srv_id, server['id']) self.assertEqual(server.share_network_id, values['share_network_id']) self.assertEqual(server.host, values['host']) self.assertEqual(server.status, values['status']) self.assertDictMatch(details, server['backend_details']) self.assertTrue('backend_details' in server.to_dict())
def setUp(self): super(ShareRpcAPITestCase, self).setUp() self.context = context.get_admin_context() share = db_utils.create_share( availability_zone=CONF.storage_availability_zone, status=constants.STATUS_AVAILABLE ) access = db_utils.create_access(share_id=share["id"]) snapshot = db_utils.create_snapshot(share_id=share["id"]) share_server = db_utils.create_share_server() cg = {"id": "fake_cg_id", "host": "fake_host"} cgsnapshot = {"id": "fake_cg_id"} host = {"host": "fake_host", "capabilities": 1} self.fake_share = jsonutils.to_primitive(share) self.fake_access = jsonutils.to_primitive(access) self.fake_snapshot = jsonutils.to_primitive(snapshot) self.fake_share_server = jsonutils.to_primitive(share_server) self.fake_cg = jsonutils.to_primitive(cg) self.fake_cgsnapshot = jsonutils.to_primitive(cgsnapshot) self.fake_host = jsonutils.to_primitive(host) self.ctxt = context.RequestContext("fake_user", "fake_project") self.rpcapi = share_rpcapi.ShareAPI()
def test_share_server_migration_get_progress(self): server = db_utils.create_share_server( id='fake_server_id', status=constants.STATUS_ACTIVE, task_state=constants.TASK_STATE_MIGRATION_SUCCESS) req = self._get_server_migration_request(server['id']) body = {'migration_get_progress': None} expected = { 'total_progress': 'fake', 'task_state': constants.TASK_STATE_MIGRATION_SUCCESS, 'destination_share_server_id': 'fake_destination_server_id' } self.mock_object(share_api.API, 'share_server_migration_get_progress', mock.Mock(return_value=expected)) response = self.controller.share_server_migration_get_progress( req, server['id'], body) self.assertEqual(expected, response) (share_api.API.share_server_migration_get_progress. assert_called_once_with(utils.IsAMatcher(ctx_api.RequestContext), server['id']))
def test_wait_for_share_server(self, status): server = db_utils.create_share_server(status=status) # mocks self.mock_object(db, 'share_server_get', mock.Mock(return_value=server)) # run if status == constants.STATUS_ACTIVE: result = self.helper.wait_for_share_server('fake_server_id') self.assertEqual(server, result) elif status == constants.STATUS_ERROR: self.assertRaises( exception.ShareServerNotCreated, self.helper.wait_for_share_server, 'fake_server_id') else: self.mock_object(time, 'sleep') self.assertRaises( exception.ShareServerNotReady, self.helper.wait_for_share_server, 'fake_server_id') # asserts db.share_server_get.assert_called_with(self.context, 'fake_server_id')
def test_share_server_migration_start(self): server = db_utils.create_share_server(id='fake_server_id', status=constants.STATUS_ACTIVE) share_network = db_utils.create_share_network() req = self._get_server_migration_request(server['id']) context = req.environ['manila.context'] self.mock_object(db_api, 'share_network_get', mock.Mock( return_value=share_network)) self.mock_object(db_api, 'share_server_get', mock.Mock(return_value=server)) self.mock_object(common, 'check_share_network_is_active', mock.Mock(return_value=True)) self.mock_object(share_api.API, 'share_server_migration_start') body = { 'migration_start': { 'host': 'fake_host', 'preserve_snapshots': True, 'writable': True, 'nondisruptive': True, 'new_share_network_id': 'fake_net_id', } } self.controller.share_server_migration_start(req, server['id'], body) db_api.share_server_get.assert_called_once_with( context, server['id']) share_api.API.share_server_migration_start.assert_called_once_with( context, server, 'fake_host', True, True, True, new_share_network=share_network) db_api.share_network_get.assert_called_once_with( context, 'fake_net_id') common.check_share_network_is_active.assert_called_once_with( share_network)
def test_cleanup_access_rules(self, exc): # mocks server = db_utils.create_share_server() share_driver = mock.Mock() self.mock_object(self.helper, 'revert_access_rules', mock.Mock(side_effect=exc)) self.mock_object(self.helper.db, 'share_instance_update') self.mock_object(migration.LOG, 'warning') # run self.helper.cleanup_access_rules(self.share_instance, server, share_driver) # asserts self.helper.revert_access_rules.assert_called_once_with( self.share_instance, server, share_driver) self.helper.db.share_instance_update.assert_called_once_with( self.context, self.share_instance['id'], {'status': constants.STATUS_INACTIVE}) if exc: self.assertEqual(1, migration.LOG.warning.call_count)
def test_revert_access_rules(self, dest_host): share_instance = db_utils.create_share_instance( share_id=self.share['id'], status=constants.STATUS_AVAILABLE) share_instance_ids = [instance['id'] for instance in [share_instance]] access = db_utils.create_access(share_id=self.share['id'], access_to='fake_ip', access_level='rw') server = db_utils.create_share_server(share_id=self.share['id']) # mocks self.mock_object(self.access_helper, 'update_access_rules') get_and_update_call = self.mock_object( self.access_helper, 'get_and_update_share_instance_access_rules', mock.Mock(return_value=[access])) mock_update_access_for_instances = self.mock_object( share_rpcapi.ShareAPI, 'update_access_for_instances') # run self.helper.revert_access_rules([share_instance], server, dest_host=dest_host) # asserts get_and_update_call.assert_called_once_with( self.context, share_instance_id=share_instance['id'], updates={'state': constants.ACCESS_STATE_QUEUED_TO_APPLY}) if dest_host: mock_update_access_for_instances.assert_called_once_with( self.context, dest_host, share_instance_ids, server) else: self.access_helper.update_access_rules.assert_called_once_with( self.context, share_instance['id'], share_server=server)
def test_wait_for_share_server(self, status): server = db_utils.create_share_server(status=status) # mocks self.mock_object(db, 'share_server_get', mock.Mock(return_value=server)) # run if status == constants.STATUS_ACTIVE: result = self.helper.wait_for_share_server('fake_server_id') self.assertEqual(server, result) elif status == constants.STATUS_ERROR: self.assertRaises(exception.ShareServerNotCreated, self.helper.wait_for_share_server, 'fake_server_id') else: self.mock_object(time, 'sleep') self.assertRaises(exception.ShareServerNotReady, self.helper.wait_for_share_server, 'fake_server_id') # asserts db.share_server_get.assert_called_with(self.context, 'fake_server_id')
def _setup_unmanage_tests(self, status=constants.STATUS_ACTIVE): server = db_utils.create_share_server(id='fake_server_id', status=status) self.mock_object(db_api, 'share_server_get', mock.Mock(return_value=server)) return server
def _setup_unmanage_tests(self, status=constants.STATUS_ACTIVE): server = db_utils.create_share_server( id='fake_server_id', status=status) self.mock_object(db_api, 'share_server_get', mock.Mock(return_value=server)) return server
def test_create(self): server = db_utils.create_share_server() self.assertTrue(server['id']) self.assertEqual(server.share_network_id, server['share_network_id']) self.assertEqual(server.host, server['host']) self.assertEqual(server.status, server['status'])
def test_delete(self): server = db_utils.create_share_server() num_records = len(db_api.share_server_get_all(self.ctxt)) db_api.share_server_delete(self.ctxt, server['id']) self.assertEqual(len(db_api.share_server_get_all(self.ctxt)), num_records - 1)