Exemplo n.º 1
0
    def setUp(self):
        super(TestProjectDelete, self).setUp()

        # This is the return value for utils.find_resource()
        self.projects_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.PROJECT),
            loaded=True,
        )
        self.projects_mock.delete.return_value = None

        # Get the command object to test
        self.cmd = project.DeleteProject(self.app, None)
Exemplo n.º 2
0
    def setUp(self):
        super(TestProjectList, self).setUp()

        self.projects_mock.list.return_value = [
            fakes.FakeResource(
                None,
                copy.deepcopy(identity_fakes.PROJECT),
                loaded=True,
            ),
        ]

        # Get the command object to test
        self.cmd = project.ListProject(self.app, None)
Exemplo n.º 3
0
    def setUp(self):
        super(TestImageCreate, self).setUp()

        self.images_mock.create.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(image_fakes.IMAGE),
            loaded=True,
        )
        # 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.CreateImage(self.app, None)
    def setUp(self):
        super(TestProjectUnset, self).setUp()

        project_dict = {'fee': 'fi', 'fo': 'fum'}
        project_dict.update(identity_fakes.PROJECT)
        self.projects_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(project_dict),
            loaded=True,
        )

        # Get the command object to test
        self.cmd = project.UnsetProject(self.app, None)
    def setUp(self):
        super(TestUserSet, self).setUp()

        self.projects_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.PROJECT),
            loaded=True,
        )

        self.users_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.USER),
            loaded=True,
        )
        self.users_mock.update.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.USER),
            loaded=True,
        )

        # Get the command object to test
        self.cmd = user.SetUser(self.app, None)
    def setUp(self):
        super(TestDomainDelete, self).setUp()

        # This is the return value for utils.find_resource()
        self.domains_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.DOMAIN),
            loaded=True,
        )
        self.domains_mock.delete.return_value = None

        # Get the command object to test
        self.cmd = domain.DeleteDomain(self.app, None)
Exemplo n.º 7
0
    def setUp(self):
        super(TestRegionList, self).setUp()

        self.regions_mock.list.return_value = [
            fakes.FakeResource(
                None,
                copy.deepcopy(identity_fakes.REGION),
                loaded=True,
            ),
        ]

        # Get the command object to test
        self.cmd = region.ListRegion(self.app, None)
Exemplo n.º 8
0
    def setUp(self):
        super(TestEndpointDelete, self).setUp()

        # This is the return value for utils.find_resource(endpoint)
        self.endpoints_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.ENDPOINT),
            loaded=True,
        )
        self.endpoints_mock.delete.return_value = None

        # Get the command object to test
        self.cmd = endpoint.DeleteEndpoint(self.app, None)
    def setUp(self):
        super(TestServiceList, self).setUp()

        self.service_mock.list.return_value = [
            fakes.FakeResource(
                None,
                copy.deepcopy(compute_fakes.SERVICE),
                loaded=True,
            )
        ]

        # Get the command object to test
        self.cmd = service.ListService(self.app, None)
Exemplo n.º 10
0
    def setUp(self):
        super(TestConsumerShow, self).setUp()

        consumer_no_secret = copy.deepcopy(identity_fakes.OAUTH_CONSUMER)
        del consumer_no_secret['secret']
        self.consumers_mock.get.return_value = fakes.FakeResource(
            None,
            consumer_no_secret,
            loaded=True,
        )

        # Get the command object to test
        self.cmd = consumer.ShowConsumer(self.app, None)
    def setUp(self):
        super(TestDomainList, self).setUp()

        self.domains_mock.list.return_value = [
            fakes.FakeResource(
                None,
                copy.deepcopy(identity_fakes.DOMAIN),
                loaded=True,
            ),
        ]

        # Get the command object to test
        self.cmd = domain.ListDomain(self.app, None)
Exemplo n.º 12
0
    def setUp(self):
        super(TestRoleList, self).setUp()

        self.roles_mock.list.return_value = [
            fakes.FakeResource(
                None,
                copy.deepcopy(identity_fakes.ROLE),
                loaded=True,
            ),
        ]

        # Get the command object to test
        self.cmd = role.ListRole(self.app, None)
Exemplo n.º 13
0
    def setUp(self):
        super(TestTypeSet, self).setUp()

        self.types_mock.get.return_value = self.volume_type

        # Return a project
        self.projects_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.PROJECT),
            loaded=True,
        )
        # Get the command object to test
        self.cmd = volume_type.SetVolumeType(self.app, None)
    def setUp(self):
        super(TestRemoveProjectImage, 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.project_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.PROJECT),
            loaded=True,
        )
        self.domain_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.DOMAIN),
            loaded=True,
        )
        self.image_members_mock.delete.return_value = None
        # Get the command object to test
        self.cmd = image.RemoveProjectImage(self.app, None)
Exemplo n.º 15
0
    def setUp(self):
        super(TestVolumeList, self).setUp()

        self.volumes_mock.list.return_value = [
            fakes.FakeResource(
                None,
                copy.deepcopy(volume_fakes.VOLUME),
                loaded=True,
            ),
        ]

        # Get the command object to test
        self.cmd = volume.ListVolume(self.app, None)
    def setUp(self):
        super(TestUserDelete, self).setUp()

        # This is the return value for utils.find_resource()
        self.users_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.USER),
            loaded=True,
        )
        self.users_mock.delete.return_value = None

        # Get the command object to test
        self.cmd = user.DeleteUser(self.app, None)
Exemplo n.º 17
0
    def setUp(self):
        super(TestProjectSet, self).setUp()

        self.domains_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.DOMAIN),
            loaded=True,
        )

        self.projects_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.PROJECT),
            loaded=True,
        )
        self.projects_mock.update.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.PROJECT),
            loaded=True,
        )

        # Get the command object to test
        self.cmd = project.SetProject(self.app, None)
Exemplo n.º 18
0
    def test_project_show_parents_and_children(self):
        project = copy.deepcopy(identity_fakes.PROJECT_WITH_PARENT)
        project['subtree'] = identity_fakes.children
        project['parents'] = identity_fakes.parents
        self.projects_mock.get.return_value = fakes.FakeResource(
            None,
            project,
            loaded=True,
        )

        arglist = [
            identity_fakes.PROJECT_WITH_PARENT['id'],
            '--parents',
            '--children',
        ]
        verifylist = [
            ('project', identity_fakes.PROJECT_WITH_PARENT['id']),
            ('parents', True),
            ('children', True),
        ]
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        columns, data = self.cmd.take_action(parsed_args)
        self.projects_mock.get.assert_called_with(
            identity_fakes.PROJECT_WITH_PARENT['id'],
            parents_as_list=True,
            subtree_as_list=True,
        )

        collist = (
            'description',
            'domain_id',
            'enabled',
            'id',
            'name',
            'parent_id',
            'parents',
            'subtree',
        )
        self.assertEqual(columns, collist)
        datalist = (
            identity_fakes.PROJECT_WITH_PARENT['description'],
            identity_fakes.PROJECT_WITH_PARENT['domain_id'],
            identity_fakes.PROJECT_WITH_PARENT['enabled'],
            identity_fakes.PROJECT_WITH_PARENT['id'],
            identity_fakes.PROJECT_WITH_PARENT['name'],
            identity_fakes.PROJECT_WITH_PARENT['parent_id'],
            identity_fakes.ids_for_parents,
            identity_fakes.ids_for_children,
        )
        self.assertEqual(data, datalist)
Exemplo n.º 19
0
    def create_one_host(attrs=None):
        """Create a fake host.

        :param Dictionary attrs:
            A dictionary with all attributes
        :return:
            A FakeResource object, with uuid and other attributes
        """
        attrs = attrs or {}

        # Set default attributes.
        host_info = {
            "service_id": 1,
            "host": "host1",
            "uuid": 'host-id-' + uuid.uuid4().hex,
            "vcpus": 10,
            "memory_mb": 100,
            "local_gb": 100,
            "vcpus_used": 5,
            "memory_mb_used": 50,
            "local_gb_used": 10,
            "hypervisor_type": "xen",
            "hypervisor_version": 1,
            "hypervisor_hostname": "devstack1",
            "free_ram_mb": 50,
            "free_disk_gb": 50,
            "current_workload": 10,
            "running_vms": 1,
            "cpu_info": "",
            "disk_available_least": 1,
            "host_ip": "10.10.10.10",
            "supported_instances": "",
            "metrics": "",
            "pci_stats": "",
            "extra_resources": "",
            "stats": "",
            "numa_topology": "",
            "ram_allocation_ratio": 1.0,
            "cpu_allocation_ratio": 1.0,
            "zone": 'zone-' + uuid.uuid4().hex,
            "host_name": 'name-' + uuid.uuid4().hex,
            "service": 'service-' + uuid.uuid4().hex,
            "cpu": 4,
            "disk_gb": 100,
            'project': 'project-' + uuid.uuid4().hex,
        }
        host_info.update(attrs)
        host = fakes.FakeResource(
            info=copy.deepcopy(host_info),
            loaded=True)
        return host
Exemplo n.º 20
0
    def create_one_network(attrs={}):
        """Create a fake network.

        :param Dictionary attrs:
            A dictionary with all attributes
        :return:
            A FakeResource object, with id, label, cidr and so on
        """
        # Set default attributes.
        network_attrs = {
            'bridge': 'br100',
            'bridge_interface': None,
            'broadcast': '10.0.0.255',
            'cidr': '10.0.0.0/24',
            'cidr_v6': None,
            'created_at': '2016-02-11T11:17:37.000000',
            'deleted': False,
            'deleted_at': None,
            'dhcp_server': '10.0.0.1',
            'dhcp_start': '10.0.0.2',
            'dns1': '8.8.4.4',
            'dns2': None,
            'enable_dhcp': True,
            'gateway': '10.0.0.1',
            'gateway_v6': None,
            'host': None,
            'id': 'network-id-' + uuid.uuid4().hex,
            'injected': False,
            'label': 'network-label-' + uuid.uuid4().hex,
            'mtu': None,
            'multi_host': False,
            'netmask': '255.255.255.0',
            'netmask_v6': None,
            'priority': None,
            'project_id': 'project-id-' + uuid.uuid4().hex,
            'rxtx_base': None,
            'share_address': False,
            'updated_at': None,
            'vlan': None,
            'vpn_private_address': None,
            'vpn_public_address': None,
            'vpn_public_port': None,
        }

        # Overwrite default attributes.
        network_attrs.update(attrs)

        network = fakes.FakeResource(info=copy.deepcopy(network_attrs),
                                     loaded=True)

        return network
Exemplo n.º 21
0
    def setUp(self):
        super(TestImageList, self).setUp()

        # This is the return value for utils.find_resource()
        self.images_mock.list.return_value = [
            fakes.FakeResource(
                None,
                copy.deepcopy(image_fakes.IMAGE),
                loaded=True,
            ),
        ]

        # Get the command object to test
        self.cmd = image.ListImage(self.app, None)
Exemplo n.º 22
0
    def setUp(self):
        super(TestMappingList, self).setUp()
        self.mapping_mock.get.return_value = fakes.FakeResource(
            None, {'id': identity_fakes.mapping_id}, loaded=True)
        # Pretend list command returns list of two mappings.
        # NOTE(marek-denis): We are returning FakeResources with mapping id
        # only as ShowMapping class is implemented in a way where rules will
        # not be displayed, only mapping ids.
        self.mapping_mock.list.return_value = [
            fakes.FakeResource(
                None,
                {'id': identity_fakes.mapping_id},
                loaded=True,
            ),
            fakes.FakeResource(
                None,
                {'id': 'extra_mapping'},
                loaded=True,
            ),
        ]

        # Get the command object to test
        self.cmd = mapping.ListMapping(self.app, None)
Exemplo n.º 23
0
    def setUp(self):
        super(TestAddProjectToImage, self).setUp()

        # This is the return value for utils.find_resource()
        self.images_mock.get.return_value = self._image

        # Update the image_id in the MEMBER dict
        self.new_member = copy.deepcopy(image_fakes.MEMBER)
        self.new_member['image_id'] = self._image.id
        self.image_members_mock.create.return_value = fakes.FakeModel(
            self.new_member, )
        self.project_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.PROJECT),
            loaded=True,
        )
        self.domain_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.DOMAIN),
            loaded=True,
        )
        # Get the command object to test
        self.cmd = image.AddProjectToImage(self.app, None)
Exemplo n.º 24
0
    def test_qos_unset_with_properties(self):
        self.qos_mock.get.return_value = fakes.FakeResource(
            None, copy.deepcopy(volume_fakes.QOS), loaded=True)
        arglist = [
            volume_fakes.qos_id, '--property', 'iops', '--property', 'foo'
        ]

        verifylist = [('qos_spec', volume_fakes.qos_id),
                      ('property', ['iops', 'foo'])]
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        self.cmd.take_action(parsed_args)
        self.qos_mock.unset_keys.assert_called_with(volume_fakes.qos_id,
                                                    ['iops', 'foo'])
Exemplo n.º 25
0
    def create_one_subnet_pool(attrs={}, methods={}):
        """Create a fake subnet pool.

        :param Dictionary attrs:
            A dictionary with all attributes
        :param Dictionary methods:
            A dictionary with all methods
        :return:
            A FakeResource object faking the subnet pool
        """
        # Set default attributes.
        subnet_pool_attrs = {
            'id': 'subnet-pool-id-' + uuid.uuid4().hex,
            'name': 'subnet-pool-name-' + uuid.uuid4().hex,
            'prefixes': ['10.0.0.0/24', '10.1.0.0/24'],
            'default_prefixlen': 8,
            'address_scope_id': 'address-scope-id-' + uuid.uuid4().hex,
            'tenant_id': 'project-id-' + uuid.uuid4().hex,
            'is_default': False,
            'shared': False,
            'max_prefixlen': 32,
            'min_prefixlen': 8,
            'default_quota': None,
            'ip_version': 4,
        }

        # Overwrite default attributes.
        subnet_pool_attrs.update(attrs)

        # Set default methods.
        subnet_pool_methods = {
            'keys': [
                'id', 'name', 'prefixes', 'default_prefixlen',
                'address_scope_id', 'tenant_id', 'is_default', 'shared',
                'max_prefixlen', 'min_prefixlen', 'default_quota', 'ip_version'
            ]
        }

        # Overwrite default methods.
        subnet_pool_methods.update(methods)

        subnet_pool = fakes.FakeResource(
            info=copy.deepcopy(subnet_pool_attrs),
            methods=copy.deepcopy(subnet_pool_methods),
            loaded=True)

        # Set attributes with special mapping in OpenStack SDK.
        subnet_pool.project_id = subnet_pool_attrs['tenant_id']

        return subnet_pool
Exemplo n.º 26
0
    def create_one_port(attrs={}):
        """Create a fake port.

        :param Dictionary attrs:
            A dictionary with all attributes
        :param Dictionary methods:
            A dictionary with all methods
        :return:
            A FakeResource object, with id, name, etc.
        """
        # Set default attributes.
        port_attrs = {
            'admin_state_up': True,
            'allowed_address_pairs': [{}],
            'binding:host_id': 'binding-host-id-' + uuid.uuid4().hex,
            'binding:profile': {},
            'binding:vif_details': {},
            'binding:vif_type': 'ovs',
            'binding:vnic_type': 'normal',
            'device_id': 'device-id-' + uuid.uuid4().hex,
            'device_owner': 'compute:nova',
            'dns_assignment': [{}],
            'dns_name': 'dns-name-' + uuid.uuid4().hex,
            'extra_dhcp_opts': [{}],
            'fixed_ips': [{}],
            'id': 'port-id-' + uuid.uuid4().hex,
            'mac_address': 'fa:16:3e:a9:4e:72',
            'name': 'port-name-' + uuid.uuid4().hex,
            'network_id': 'network-id-' + uuid.uuid4().hex,
            'port_security_enabled': True,
            'security_groups': [],
            'status': 'ACTIVE',
            'tenant_id': 'project-id-' + uuid.uuid4().hex,
        }

        # Overwrite default attributes.
        port_attrs.update(attrs)

        port = fakes.FakeResource(info=copy.deepcopy(port_attrs),
                                  loaded=True)

        # Set attributes with special mappings in OpenStack SDK.
        port.project_id = port_attrs['tenant_id']
        port.binding_host_id = port_attrs['binding:host_id']
        port.binding_profile = port_attrs['binding:profile']
        port.binding_vif_details = port_attrs['binding:vif_details']
        port.binding_vif_type = port_attrs['binding:vif_type']
        port.binding_vnic_type = port_attrs['binding:vnic_type']

        return port
Exemplo n.º 27
0
    def setUp(self):
        super(TestRoleAssignment, self).setUp()

        # Get a shortcut to the UserManager Mock
        self.users_mock = self.app.client_manager.identity.users
        self.users_mock.reset_mock()

        # Get a shortcut to the ProjectManager Mock
        self.projects_mock = self.app.client_manager.identity.projects
        self.projects_mock.reset_mock()

        # Get a shortcut to the RoleManager Mock
        self.roles_mock = self.app.client_manager.identity.roles
        self.roles_mock.reset_mock()

        self.projects_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.PROJECT),
            loaded=True,
        )

        self.users_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.USER),
            loaded=True,
        )

        self.roles_mock.roles_for_user.return_value = [
            fakes.FakeResource(
                None,
                copy.deepcopy(identity_fakes.ROLE),
                loaded=True,
            ),
        ]

        # Get the command object to test
        self.cmd = role_assignment.ListRoleAssignment(self.app, None)
Exemplo n.º 28
0
    def create_one_network(attrs={}, methods={}):
        """Create a fake network.

        :param Dictionary attrs:
            A dictionary with all attributes
        :param Dictionary methods:
            A dictionary with all methods
        :return:
            A FakeResource object, with id, name, admin_state_up,
            router_external, status, subnets, tenant_id
        """
        # Set default attributes.
        network_attrs = {
            'id': 'network-id-' + uuid.uuid4().hex,
            'name': 'network-name-' + uuid.uuid4().hex,
            'status': 'ACTIVE',
            'tenant_id': 'project-id-' + uuid.uuid4().hex,
            'admin_state_up': True,
            'shared': False,
            'subnets': ['a', 'b'],
            'provider_network_type': 'vlan',
            'router_external': True,
            'availability_zones': [],
            'availability_zone_hints': [],
        }

        # Overwrite default attributes.
        network_attrs.update(attrs)

        # Set default methods.
        network_methods = {
            'keys': [
                'id', 'name', 'admin_state_up', 'router_external', 'status',
                'subnets', 'tenant_id', 'availability_zones',
                'availability_zone_hints'
            ],
        }

        # Overwrite default methods.
        network_methods.update(methods)

        network = fakes.FakeResource(info=copy.deepcopy(network_attrs),
                                     methods=copy.deepcopy(network_methods),
                                     loaded=True)

        # Set attributes with special mapping in OpenStack SDK.
        network.project_id = network_attrs['tenant_id']

        return network
    def setUp(self):
        super(TestShowSecurityGroupRuleCompute, self).setUp()

        self.app.client_manager.network_endpoint_enabled = False

        # Build a security group fake customized for this test.
        security_group_rules = [self._security_group_rule._info]
        security_group = fakes.FakeResource(info=copy.deepcopy(
            {'rules': security_group_rules}),
                                            loaded=True)
        security_group.rules = security_group_rules
        self.compute.security_groups.list.return_value = [security_group]

        # Get the command object to test
        self.cmd = security_group_rule.ShowSecurityGroupRule(self.app, None)
Exemplo n.º 30
0
    def setUp(self):
        super(TestRoleRemove, self).setUp()

        self.users_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.USER),
            loaded=True,
        )

        self.groups_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.GROUP),
            loaded=True,
        )

        self.domains_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.DOMAIN),
            loaded=True,
        )

        self.projects_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.PROJECT),
            loaded=True,
        )

        self.roles_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.ROLE),
            loaded=True,
        )
        self.roles_mock.revoke.return_value = None

        # Get the command object to test
        self.cmd = role.RemoveRole(self.app, None)