def create_one_pool(attrs=None): """Create a fake pool. :param Dictionary attrs: A dictionary with all attributes of the pool :return: A FakeResource object with pool name and attrs. """ # Set default attribute pool_info = { 'name': 'host@lvmdriver-1#lvmdriver-1', 'storage_protocol': 'iSCSI', 'thick_provisioning_support': False, 'thin_provisioning_support': True, 'total_volumes': 99, 'total_capacity_gb': 1000.00, 'allocated_capacity_gb': 100, 'max_over_subscription_ratio': 200.0, } # Overwrite default attributes if there are some attributes set pool_info.update(attrs or {}) pool = fakes.FakeResource(None, pool_info, loaded=True) return pool
def create_one_encryption_type(attrs=None): """Create a fake encryption type. :param Dictionary attrs: A dictionary with all attributes :return: A FakeResource object with volume_type_id etc. """ attrs = attrs or {} # Set default attributes. encryption_info = { "volume_type_id": 'type-id-' + uuid.uuid4().hex, 'provider': 'LuksEncryptor', 'cipher': None, 'key_size': None, 'control_location': 'front-end', } # Overwrite default attributes. encryption_info.update(attrs) encryption_type = fakes.FakeResource( info=copy.deepcopy(encryption_info), loaded=True) return encryption_type
def create_one_service(attrs=None): """Create a fake service. :param Dictionary attrs: A dictionary with all attributes of service :return: A FakeResource object with host, status, etc. """ # Set default attribute service_info = { 'host': 'host_test', 'binary': 'cinder_test', 'status': 'enabled', 'disabled_reason': 'LongHoliday-GoldenWeek', 'zone': 'fake_zone', 'updated_at': 'fake_date', 'state': 'fake_state', } # Overwrite default attributes if there are some attributes set attrs = attrs or {} service_info.update(attrs) service = fakes.FakeResource(None, service_info, loaded=True) return service
def setUp(self): super(TestIdentityProviderCreate, self).setUp() copied_idp = copy.deepcopy(identity_fakes.IDENTITY_PROVIDER) resource = fakes.FakeResource(None, copied_idp, loaded=True) self.identity_providers_mock.create.return_value = resource self.cmd = identity_provider.CreateIdentityProvider(self.app, None)
def prepare(self): """Prepare fake return objects before the test is executed""" resources = fakes.FakeResource( None, copy.deepcopy(identity_fakes.IDENTITY_PROVIDER), loaded=True) self.identity_providers_mock.update.return_value = resources
def create_one_snapshot(attrs=None): """Create a fake snapshot. :param Dictionary attrs: A dictionary with all attributes :return: A FakeResource object with id, name, description, etc. """ attrs = attrs or {} # Set default attributes. snapshot_info = { "id": 'snapshot-id-' + uuid.uuid4().hex, "display_name": 'snapshot-name-' + uuid.uuid4().hex, "display_description": 'snapshot-description-' + uuid.uuid4().hex, "size": 10, "status": "available", "metadata": { "foo": "bar" }, "created_at": "2015-06-03T18:49:19.000000", "volume_id": 'vloume-id-' + uuid.uuid4().hex, } # Overwrite default attributes. snapshot_info.update(attrs) snapshot_method = {'update': None} snapshot = fakes.FakeResource(info=copy.deepcopy(snapshot_info), methods=copy.deepcopy(snapshot_method), loaded=True) return snapshot
def create_one_backup(attrs=None): """Create a fake backup. :param Dictionary attrs: A dictionary with all attributes :return: A FakeResource object with id, name, volume_id, etc. """ attrs = attrs or {} # Set default attributes. backup_info = { "id": 'backup-id-' + uuid.uuid4().hex, "name": 'backup-name-' + uuid.uuid4().hex, "volume_id": 'volume-id-' + uuid.uuid4().hex, "snapshot_id": 'snapshot-id' + uuid.uuid4().hex, "description": 'description-' + uuid.uuid4().hex, "object_count": None, "container": 'container-' + uuid.uuid4().hex, "size": random.randint(1, 20), "status": "error", "availability_zone": 'zone' + uuid.uuid4().hex, } # Overwrite default attributes. backup_info.update(attrs) backup = fakes.FakeResource(info=copy.deepcopy(backup_info), loaded=True) return backup
def create_one_consistency_group(attrs=None): """Create a fake consistency group. :param Dictionary attrs: A dictionary with all attributes :return: A FakeResource object with id, name, description, etc. """ attrs = attrs or {} # Set default attributes. consistency_group_info = { "id": 'backup-id-' + uuid.uuid4().hex, "name": 'backup-name-' + uuid.uuid4().hex, "description": 'description-' + uuid.uuid4().hex, "status": "error", "availability_zone": 'zone' + uuid.uuid4().hex, "created_at": 'time-' + uuid.uuid4().hex, "volume_types": ['volume-type1'], } # Overwrite default attributes. consistency_group_info.update(attrs) consistency_group = fakes.FakeResource( info=copy.deepcopy(consistency_group_info), loaded=True) return consistency_group
def create_one_qos(attrs=None): """Create a fake Qos specification. :param Dictionary attrs: A dictionary with all attributes :return: A FakeResource object with id, name, consumer, etc. """ attrs = attrs or {} # Set default attributes. qos_info = { "id": 'qos-id-' + uuid.uuid4().hex, "name": 'qos-name-' + uuid.uuid4().hex, "consumer": 'front-end', "specs": { "foo": "bar", "iops": "9001" }, } # Overwrite default attributes. qos_info.update(attrs) qos = fakes.FakeResource(info=copy.deepcopy(qos_info), loaded=True) return qos
def create_one_type(attrs=None, methods=None): """Create a fake type. :param Dictionary attrs: A dictionary with all attributes :param Dictionary methods: A dictionary with all methods :return: A FakeResource object with id, name, description, etc. """ attrs = attrs or {} methods = methods or {} # Set default attributes. type_info = { "id": 'type-id-' + uuid.uuid4().hex, "name": 'type-name-' + uuid.uuid4().hex, "description": 'type-description-' + uuid.uuid4().hex, "extra_specs": { "foo": "bar" }, "is_public": True, } # Overwrite default attributes. type_info.update(attrs) volume_type = fakes.FakeResource(info=copy.deepcopy(type_info), methods=methods, loaded=True) return volume_type
def test_role_assignment_list_project_and_user(self): self.roles_mock.roles_for_user.return_value = [ fakes.FakeResource( None, copy.deepcopy( identity_fakes.ROLE), loaded=True, ), fakes.FakeResource( None, copy.deepcopy( identity_fakes.ROLE_2), loaded=True, ), ] arglist = [ '--project', identity_fakes.project_name, '--user', identity_fakes.user_name, ] verifylist = [ ('user', identity_fakes.user_name), ('project', identity_fakes.project_name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) # In base command class Lister in cliff, abstract method take_action() # returns a tuple containing the column names and an iterable # containing the data to be listed. columns, data = self.cmd.take_action(parsed_args) self.roles_mock.roles_for_user.assert_called_with( identity_fakes.user_id, identity_fakes.project_id, ) self.assertEqual(self.columns, columns) datalist = (( identity_fakes.role_id, identity_fakes.user_id, identity_fakes.project_id, ), (identity_fakes.ROLE_2['id'], identity_fakes.user_id, identity_fakes.project_id, ),) self.assertEqual(datalist, tuple(data))
def create_one_network(attrs=None): """Create a fake network. :param Dictionary attrs: A dictionary with all attributes :return: A FakeResource object, with id, name, etc. """ attrs = attrs or {} # Set default attributes. network_attrs = { 'id': 'network-id-' + uuid.uuid4().hex, 'name': 'network-name-' + uuid.uuid4().hex, 'status': 'ACTIVE', 'description': 'network-description-' + uuid.uuid4().hex, 'tenant_id': 'project-id-' + uuid.uuid4().hex, 'admin_state_up': True, 'shared': False, 'subnets': ['a', 'b'], 'provider:network_type': 'vlan', 'provider:physical_network': 'physnet1', 'provider:segmentation_id': "400", 'router:external': True, 'availability_zones': [], 'availability_zone_hints': [], 'is_default': False, 'port_security_enabled': True, 'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex, 'ipv4_address_scope': 'ipv4' + uuid.uuid4().hex, 'ipv6_address_scope': 'ipv6' + uuid.uuid4().hex, } # Overwrite default attributes. network_attrs.update(attrs) network = fakes.FakeResource(info=copy.deepcopy(network_attrs), loaded=True) # Set attributes with special mapping in OpenStack SDK. network.project_id = network_attrs['tenant_id'] network.is_router_external = network_attrs['router:external'] network.is_admin_state_up = network_attrs['admin_state_up'] network.is_port_security_enabled = \ network_attrs['port_security_enabled'] network.subnet_ids = network_attrs['subnets'] network.is_shared = network_attrs['shared'] network.provider_network_type = \ network_attrs['provider:network_type'] network.provider_physical_network = \ network_attrs['provider:physical_network'] network.provider_segmentation_id = \ network_attrs['provider:segmentation_id'] network.ipv4_address_scope_id = \ network_attrs['ipv4_address_scope'] network.ipv6_address_scope_id = \ network_attrs['ipv6_address_scope'] return network
def setUp(self): super(TestImageSet, self).setUp() # This is the return value for utils.find_resource() self.images_mock.get.return_value = fakes.FakeResource( None, copy.deepcopy(image_fakes.IMAGE), loaded=True, ) self.images_mock.update.return_value = fakes.FakeResource( None, copy.deepcopy(image_fakes.IMAGE), loaded=True, ) # Get the command object to test self.cmd = image.SetImage(self.app, None)
def prepare(self): """Prepare fake return objects before the test is executed""" resources = fakes.FakeResource( None, copy.deepcopy(service_fakes.SERVICE_PROVIDER), loaded=True ) self.service_providers_mock.update.return_value = resources
def setUp(self): super(TestRoleCreate, self).setUp() self.domains_mock.get.return_value = fakes.FakeResource( None, copy.deepcopy(identity_fakes.DOMAIN), loaded=True, ) self.roles_mock.create.return_value = fakes.FakeResource( None, copy.deepcopy(identity_fakes.ROLE), loaded=True, ) # Get the command object to test self.cmd = role.CreateRole(self.app, None)
def setUp(self): super(TestMappingCreate, self).setUp() self.mapping_mock.create.return_value = fakes.FakeResource( None, copy.deepcopy(identity_fakes.MAPPING_RESPONSE), loaded=True ) self.cmd = mapping.CreateMapping(self.app, None)
def setUp(self): super(TestMappingSet, self).setUp() self.mapping_mock.get.return_value = fakes.FakeResource( None, copy.deepcopy(identity_fakes.MAPPING_RESPONSE), loaded=True ) self.mapping_mock.update.return_value = fakes.FakeResource( None, identity_fakes.MAPPING_RESPONSE_2, loaded=True ) # Get the command object to test self.cmd = mapping.SetMapping(self.app, None)
def prepare(self): """Prepare fake return objects before the test is executed""" self.new_remote_id = 'new_entity' updated_idp = copy.deepcopy(identity_fakes.IDENTITY_PROVIDER) updated_idp['remote_ids'] = [self.new_remote_id] resources = fakes.FakeResource(None, updated_idp, loaded=True) self.identity_providers_mock.update.return_value = resources
def test_image_update_volume(self): # Set up VolumeManager Mock volumes_mock = self.app.client_manager.volume.volumes volumes_mock.reset_mock() volumes_mock.get.return_value = fakes.FakeResource( None, copy.deepcopy({'id': 'vol1', 'name': 'volly'}), loaded=True, ) response = { "id": 'volume_id', "updated_at": 'updated_at', "status": 'uploading', "display_description": 'desc', "size": 'size', "volume_type": 'volume_type', "container_format": image.DEFAULT_CONTAINER_FORMAT, "disk_format": image.DEFAULT_DISK_FORMAT, "image": self._image.name, } full_response = {"os-volume_upload_image": response} volumes_mock.upload_to_image.return_value = (201, full_response) arglist = [ '--volume', 'volly', '--name', 'updated_image', self._image.name, ] verifylist = [ ('private', False), ('protected', False), ('public', False), ('unprotected', False), ('volume', 'volly'), ('force', False), ('name', 'updated_image'), ('image', self._image.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) # VolumeManager.upload_to_image(volume, force, image_name, # container_format, disk_format) volumes_mock.upload_to_image.assert_called_with( 'vol1', False, self._image.name, '', '', ) # ImageManager.update(image_id, remove_props=, **) self.images_mock.update.assert_called_with( self._image.id, name='updated_image', volume='volly', ) self.assertIsNone(result)
def test_role_assignment_list_no_filters(self): self.role_assignments_mock.list.return_value = [ fakes.FakeResource( None, copy.deepcopy( identity_fakes.ASSIGNMENT_WITH_PROJECT_ID_AND_USER_ID), loaded=True, ), fakes.FakeResource( None, copy.deepcopy( identity_fakes.ASSIGNMENT_WITH_PROJECT_ID_AND_GROUP_ID), loaded=True, ), ] arglist = [] verifylist = [] parsed_args = self.check_parser(self.cmd, arglist, verifylist) # In base command class Lister in cliff, abstract method take_action() # returns a tuple containing the column names and an iterable # containing the data to be listed. columns, data = self.cmd.take_action(parsed_args) self.role_assignments_mock.list.assert_called_with( domain=None, system=None, group=None, effective=False, role=None, user=None, project=None, os_inherit_extension_inherited_to=None, include_names=False) self.assertEqual(self.columns, columns) datalist = ( (identity_fakes.role_id, identity_fakes.user_id, '', identity_fakes.project_id, '', '', False), (identity_fakes.role_id, '', identity_fakes.group_id, identity_fakes.project_id, '', '', False), ) self.assertEqual(datalist, tuple(data))
def setUp(self): super(TestConsumerList, self).setUp() self.consumers_mock.get.return_value = fakes.FakeResource( None, copy.deepcopy(identity_fakes.OAUTH_CONSUMER), loaded=True, ) self.consumers_mock.list.return_value = [ fakes.FakeResource( None, copy.deepcopy(identity_fakes.OAUTH_CONSUMER), loaded=True, ), ] # Get the command object to test self.cmd = consumer.ListConsumer(self.app, None)
def setUp(self): super(TestServiceProviderList, self).setUp() self.service_providers_mock.get.return_value = fakes.FakeResource( None, copy.deepcopy(service_fakes.SERVICE_PROVIDER), loaded=True, ) self.service_providers_mock.list.return_value = [ fakes.FakeResource( None, copy.deepcopy(service_fakes.SERVICE_PROVIDER), loaded=True, ), ] # Get the command object to test self.cmd = service_provider.ListServiceProvider(self.app, None)
def setUp(self): super(TestConsumerSet, self).setUp() self.consumers_mock.get.return_value = fakes.FakeResource( None, copy.deepcopy(identity_fakes.OAUTH_CONSUMER), loaded=True, ) consumer_updated = copy.deepcopy(identity_fakes.OAUTH_CONSUMER) consumer_updated['description'] = "consumer new description" self.consumers_mock.update.return_value = fakes.FakeResource( None, consumer_updated, loaded=True, ) self.cmd = consumer.SetConsumer(self.app, None)
def setUp(self): super(TestIdentityProviderList, self).setUp() self.identity_providers_mock.get.return_value = fakes.FakeResource( None, copy.deepcopy(identity_fakes.IDENTITY_PROVIDER), loaded=True, ) self.identity_providers_mock.list.return_value = [ fakes.FakeResource( None, copy.deepcopy(identity_fakes.IDENTITY_PROVIDER), loaded=True, ), ] # Get the command object to test self.cmd = identity_provider.ListIdentityProvider(self.app, None)
def create_one_volume_attachment(attrs=None): """Create a fake volume attachment. :param attrs: A dictionary with all attributes of volume attachment :return: A FakeResource object with id, status, etc. """ attrs = attrs or {} attachment_id = uuid.uuid4().hex volume_id = attrs.pop('volume_id', None) or uuid.uuid4().hex server_id = attrs.pop('instance', None) or uuid.uuid4().hex # Set default attribute attachment_info = { 'id': attachment_id, 'volume_id': volume_id, 'instance': server_id, 'status': random.choice([ 'attached', 'attaching', 'detached', 'reserved', 'error_attaching', 'error_detaching', 'deleted', ]), 'attach_mode': random.choice(['ro', 'rw']), 'attached_at': '2015-09-16T09:28:52.000000', 'detached_at': None, 'connection_info': { 'access_mode': 'rw', 'attachment_id': attachment_id, 'auth_method': 'CHAP', 'auth_password': '******', 'auth_username': '******', 'cacheable': False, 'driver_volume_type': 'iscsi', 'encrypted': False, 'qos_specs': None, 'target_discovered': False, 'target_iqn': f'iqn.2010-10.org.openstack:volume-{attachment_id}', 'target_lun': '1', 'target_portal': '192.168.122.170:3260', 'volume_id': volume_id, }, } # Overwrite default attributes if there are some attributes set attachment_info.update(attrs) attachment = fakes.FakeResource( None, attachment_info, loaded=True) return attachment
def setUp(self): super(TestLimitList, self).setUp() self.limit_mock.list.return_value = [ fakes.FakeResource(None, copy.deepcopy(identity_fakes.LIMIT), loaded=True) ] self.cmd = limit.ListLimit(self.app, None)
def setUp(self): super(TestAccessTokenCreate, self).setUp() self.access_tokens_mock.create.return_value = fakes.FakeResource( None, copy.deepcopy(identity_fakes.OAUTH_ACCESS_TOKEN), loaded=True, ) self.cmd = token.CreateAccessToken(self.app, None)
def setUp(self): super(TestConsumerCreate, self).setUp() self.consumers_mock.create.return_value = fakes.FakeResource( None, copy.deepcopy(identity_fakes.OAUTH_CONSUMER), loaded=True, ) self.cmd = consumer.CreateConsumer(self.app, None)
def test_role_assignment_list_def_creds(self): auth_ref = self.app.client_manager.auth_ref = mock.Mock() auth_ref.project_id.return_value = identity_fakes.project_id auth_ref.user_id.return_value = identity_fakes.user_id self.role_assignments_mock.list.return_value = [ fakes.FakeResource( None, copy.deepcopy( identity_fakes.ASSIGNMENT_WITH_PROJECT_ID_AND_USER_ID), loaded=True, ), ] arglist = [ '--auth-user', '--auth-project', ] verifylist = [ ('user', None), ('group', None), ('system', None), ('domain', None), ('project', None), ('role', None), ('effective', False), ('inherited', False), ('names', False), ('authuser', True), ('authproject', True), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) # In base command class Lister in cliff, abstract method take_action() # returns a tuple containing the column names and an iterable # containing the data to be listed. columns, data = self.cmd.take_action(parsed_args) self.role_assignments_mock.list.assert_called_with( domain=None, system=None, user=self.users_mock.get(), group=None, project=self.projects_mock.get(), role=None, effective=False, os_inherit_extension_inherited_to=None, include_names=False) self.assertEqual(self.columns, columns) datalist = ((identity_fakes.role_id, identity_fakes.user_id, '', identity_fakes.project_id, '', '', False), ) self.assertEqual(datalist, tuple(data))
def setUp(self): super(TestRoleShow, self).setUp() self.roles_mock.get.return_value = fakes.FakeResource( None, copy.deepcopy(identity_fakes.ROLE), loaded=True, ) # Get the command object to test self.cmd = role.ShowRole(self.app, None)