Python oslo_utils.uuidutils.generate_uuid() Examples

The following are 30 code examples of oslo_utils.uuidutils.generate_uuid(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module oslo_utils.uuidutils , or try the search function .
Example #1
Source File: test_hosts.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_get_all_hosts_with_pagination_marker(self, mock_host_list,
                                                  mock_policy):
        mock_policy.return_value = True
        host_list = []
        for id_ in range(4):
            test_host = utils.create_test_compute_node(
                context=self.context,
                uuid=uuidutils.generate_uuid(),
                rp_uuid=uuidutils.generate_uuid())
            numat = numa.NUMATopology._from_dict(test_host['numa_topology'])
            test_host['numa_topology'] = numat
            host = objects.ComputeNode(self.context, **test_host)
            host_list.append(host)
        mock_host_list.return_value = host_list[-1:]
        response = self.get('/v1/hosts?limit=3&marker=%s'
                            % host_list[2].uuid)

        self.assertEqual(200, response.status_int)
        actual_hosts = response.json['hosts']
        self.assertEqual(1, len(actual_hosts))
        self.assertEqual(host_list[-1].uuid,
                         actual_hosts[0].get('uuid')) 
Example #2
Source File: test_registry.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_list_registries(self):
        uuids = []
        passwords = []
        for i in range(1, 6):
            password = 'pass' + str(i)
            passwords.append(password)
            registry = utils.create_test_registry(
                uuid=uuidutils.generate_uuid(),
                context=self.context,
                name='registry' + str(i),
                password=password)
            uuids.append(str(registry['uuid']))
        res = dbapi.list_registries(self.context)
        res_uuids = [r.uuid for r in res]
        self.assertEqual(sorted(uuids), sorted(res_uuids))
        res_passwords = [r.password for r in res]
        self.assertEqual(sorted(passwords), sorted(res_passwords)) 
Example #3
Source File: test_registry.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_list_registries_sorted(self):
        uuids = []
        for i in range(5):
            registry = utils.create_test_registry(
                uuid=uuidutils.generate_uuid(),
                context=self.context,
                name='registry' + str(i))
            uuids.append(str(registry.uuid))
        res = dbapi.list_registries(self.context, sort_key='uuid')
        res_uuids = [r.uuid for r in res]
        self.assertEqual(sorted(uuids), res_uuids)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_registries,
                          self.context,
                          sort_key='foo') 
Example #4
Source File: test_container.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_refresh(self):
        uuid = self.fake_container['uuid']
        container_type = self.fake_container['container_type']
        new_uuid = uuidutils.generate_uuid()
        returns = [dict(self.fake_container, uuid=uuid),
                   dict(self.fake_container, uuid=new_uuid)]
        expected = [mock.call(self.context, container_type, uuid),
                    mock.call(self.context, container_type, uuid)]
        with mock.patch.object(self.dbapi, 'get_container_by_uuid',
                               side_effect=returns,
                               autospec=True) as mock_get_container:
            container = objects.Container.get_by_uuid(self.context, uuid)
            self.assertEqual(uuid, container.uuid)
            container.refresh()
            self.assertEqual(new_uuid, container.uuid)
            self.assertEqual(expected, mock_get_container.call_args_list)
            self.assertEqual(self.context, container._context) 
Example #5
Source File: api.py    From zun with Apache License 2.0 6 votes vote down vote up
def create_registry(self, context, values):
        # ensure defaults are present for new registries
        if not values.get('uuid'):
            values['uuid'] = uuidutils.generate_uuid()

        original_password = values.get('password')
        if original_password:
            values['password'] = crypt.encrypt(values.get('password'))

        registry = models.Registry()
        registry.update(values)
        try:
            registry.save()
        except db_exc.DBDuplicateEntry:
            raise exception.RegistryAlreadyExists(
                field='UUID', value=values['uuid'])

        if original_password:
            # the password is encrypted but we want to return the original
            # password
            registry['password'] = original_password

        return registry 
Example #6
Source File: test_allocation.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_list_allocations_sorted(self):
        cids = []
        for i in range(5):
            provider = utils.create_test_resource_provider(
                id=i,
                uuid=uuidutils.generate_uuid(),
                context=self.context)
            allocation = utils.create_test_allocation(
                id=i,
                resource_provider_id=provider.id,
                consumer_id=uuidutils.generate_uuid(),
                context=self.context)
            cids.append(allocation['consumer_id'])
        res = dbapi.list_allocations(self.context,
                                     sort_key='consumer_id')
        res_cids = [r.consumer_id for r in res]
        self.assertEqual(sorted(cids), res_cids)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_allocations,
                          self.context,
                          sort_key='foo') 
Example #7
Source File: test_resource_provider.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_refresh(self):
        uuid = self.fake_provider['uuid']
        new_uuid = uuidutils.generate_uuid()
        returns = [dict(self.fake_provider, uuid=uuid),
                   dict(self.fake_provider, uuid=new_uuid)]
        expected = [mock.call(self.context, uuid),
                    mock.call(self.context, uuid)]
        with mock.patch.object(self.dbapi, 'get_resource_provider',
                               side_effect=returns,
                               autospec=True) as mock_get_resource_provider:
            provider = objects.ResourceProvider.get_by_uuid(self.context, uuid)
            self.assertEqual(uuid, provider.uuid)
            provider.refresh()
            self.assertEqual(new_uuid, provider.uuid)
            self.assertEqual(
                expected, mock_get_resource_provider.call_args_list)
            self.assertEqual(self.context, provider._context) 
Example #8
Source File: test_container_action.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_container_actions_get_by_container(self):
        """Ensure we can get actions by UUID."""
        uuid1 = uuidutils.generate_uuid()

        expected = []

        action_values = self._create_action_values(uuid1)
        action = dbapi.action_start(self.context, action_values)
        expected.append(action)

        action_values['action'] = 'test-action'
        action = dbapi.action_start(self.context, action_values)
        expected.append(action)

        # Create an other container action.
        uuid2 = uuidutils.generate_uuid()
        action_values = self._create_action_values(uuid2, 'test-action')
        dbapi.action_start(self.context, action_values)

        actions = dbapi.actions_get(self.context, uuid1)
        self._assertEqualListsOfObjects(expected, actions) 
Example #9
Source File: test_inventory.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_list_inventories_sorted(self):
        totals = []
        for i in range(5):
            provider = utils.create_test_resource_provider(
                id=i,
                uuid=uuidutils.generate_uuid(),
                context=self.context)
            inventory = utils.create_test_inventory(
                id=i,
                resource_provider_id=provider.id,
                total=10 - i,
                context=self.context)
            totals.append(inventory['total'])
        res = dbapi.list_inventories(self.context,
                                     sort_key='total')
        res_totals = [r.total for r in res]
        self.assertEqual(sorted(totals), res_totals)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_inventories,
                          self.context,
                          sort_key='foo') 
Example #10
Source File: test_images.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_get_all_images_with_pagination_marker(
            self, mock_image_list, mock_policy_enforce):
        image_list = []
        for id_ in range(4):
            test_image = utils.create_test_image(
                context=self.context,
                id=id_,
                repo='testrepo' + str(id_),
                uuid=uuidutils.generate_uuid())
            image_list.append(objects.Image(self.context, **test_image))
        mock_image_list.return_value = image_list[-1:]
        response = self.get('/v1/images/?limit=3&marker=%s'
                            % image_list[2].uuid)

        self.assertEqual(200, response.status_int)
        actual_images = response.json['images']
        self.assertEqual(1, len(actual_images))
        self.assertEqual(image_list[-1].uuid,
                         actual_images[0].get('uuid')) 
Example #11
Source File: test_registries.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_get_all_registries_with_pagination_marker(self,
                                                       mock_registry_list):
        registry_list = []
        for id_ in range(4):
            test_registry = utils.create_test_registry(
                id=id_, uuid=uuidutils.generate_uuid(),
                name='registry' + str(id_), context=self.context)
            registry_list.append(objects.Registry(self.context,
                                                  **test_registry))
        mock_registry_list.return_value = registry_list[-1:]
        response = self.get('/v1/registries/?limit=3&marker=%s'
                            % registry_list[2].uuid)

        self.assertEqual(200, response.status_int)
        actual_registries = response.json['registries']
        self.assertEqual(1, len(actual_registries))
        self.assertEqual(registry_list[-1].uuid,
                         actual_registries[0].get('uuid')) 
Example #12
Source File: test_volume_mapping.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_list_volume_mappings_sorted(self):
        uuids = []
        for i in range(5):
            volume = utils.create_test_volume(
                uuid=uuidutils.generate_uuid(),
                context=self.context)
            volume_mapping = utils.create_test_volume_mapping(
                uuid=uuidutils.generate_uuid(),
                volume_id=volume.id,
                context=self.context)
            uuids.append(str(volume_mapping.uuid))
        res = dbapi.list_volume_mappings(self.context, sort_key='uuid')
        res_uuids = [r.uuid for r in res]
        self.assertEqual(sorted(uuids), res_uuids)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_volume_mappings,
                          self.context,
                          sort_key='foo') 
Example #13
Source File: test_inventory.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_list_inventories(self):
        totals = []
        for i in range(1, 6):
            provider = utils.create_test_resource_provider(
                id=i,
                uuid=uuidutils.generate_uuid(),
                context=self.context)
            inventory = utils.create_test_inventory(
                id=i,
                resource_provider_id=provider.id,
                total=i,
                context=self.context)
            totals.append(inventory['total'])
        res = dbapi.list_inventories(self.context)
        res_totals = [r.total for r in res]
        self.assertEqual(sorted(totals), sorted(res_totals)) 
Example #14
Source File: test_container.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_update_container_with_the_same_name(self):
        CONF.set_override("unique_container_name_scope", "project",
                          group="compute")
        container1 = utils.create_test_container(
            name='container-one',
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        container2 = utils.create_test_container(
            name='container-two',
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        new_name = 'new_name'
        dbapi.update_container(self.context, container1.container_type,
                               container1.id,
                               {'name': new_name})
        self.assertRaises(exception.ContainerAlreadyExists,
                          dbapi.update_container, self.context,
                          container2.container_type,
                          container2.id, {'name': new_name}) 
Example #15
Source File: test_container.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_list_containers_sorted(self):
        uuids = []
        for i in range(5):
            container = utils.create_test_container(
                uuid=uuidutils.generate_uuid(),
                context=self.context,
                name='container' + str(i))
            uuids.append(str(container.uuid))
        res = dbapi.list_containers(
            self.context, consts.TYPE_CONTAINER, sort_key='uuid')
        res_uuids = [r.uuid for r in res]
        self.assertEqual(sorted(uuids), res_uuids)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_containers,
                          self.context,
                          consts.TYPE_CONTAINER,
                          sort_key='foo') 
Example #16
Source File: test_image.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_list_images_with_filters(self):
        image1 = utils.create_test_image(
            context=self.context, repo='image-one',
            uuid=uuidutils.generate_uuid())
        image2 = utils.create_test_image(
            context=self.context, repo='image-two',
            uuid=uuidutils.generate_uuid())

        res = self.dbapi.list_images(self.context,
                                     filters={'repo': 'image-one'})
        self.assertEqual([image1.id], [r.id for r in res])

        res = self.dbapi.list_images(self.context,
                                     filters={'repo': 'image-two'})
        self.assertEqual([image2.id], [r.id for r in res])

        res = self.dbapi.list_images(self.context,
                                     filters={'repo': 'bad-image'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.list_images(
            self.context,
            filters={'repo': image1.repo})
        self.assertEqual([image1.id], [r.id for r in res]) 
Example #17
Source File: test_resource_provider.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_list_resource_providers_sorted(self):
        uuids = []
        for i in range(5):
            provider = utils.create_test_resource_provider(
                uuid=uuidutils.generate_uuid(),
                context=self.context,
                name='provider' + str(i))
            uuids.append(str(provider.uuid))
        res = dbapi.list_resource_providers(self.context, sort_key='uuid')
        res_uuids = [r.uuid for r in res]
        self.assertEqual(sorted(uuids), res_uuids)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_resource_providers,
                          self.context,
                          sort_key='foo') 
Example #18
Source File: provider_tree.py    From zun with Apache License 2.0 6 votes vote down vote up
def __init__(self, name, uuid=None, generation=None, parent_uuid=None):
        if uuid is None:
            uuid = uuidutils.generate_uuid()
        self.uuid = uuid
        self.name = name
        self.generation = generation
        self.parent_uuid = parent_uuid
        # Contains a dict, keyed by uuid of child resource providers having
        # this provider as a parent
        self.children = {}
        # dict of inventory records, keyed by resource class
        self.inventory = {}
        # Set of trait names
        self.traits = set()
        # Set of aggregate UUIDs
        self.aggregates = set() 
Example #19
Source File: test_compute_host.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_list_compute_nodes_sorted(self):
        uuids = []
        for i in range(5):
            node = utils.create_test_compute_node(
                uuid=uuidutils.generate_uuid(),
                rp_uuid=uuidutils.generate_uuid(),
                context=self.context,
                hostname='node' + str(i))
            uuids.append(str(node.uuid))
        res = dbapi.list_compute_nodes(self.context, sort_key='uuid')
        res_uuids = [r.uuid for r in res]
        self.assertEqual(sorted(uuids), res_uuids)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_compute_nodes,
                          self.context,
                          sort_key='foo') 
Example #20
Source File: test_resource_class.py    From zun with Apache License 2.0 6 votes vote down vote up
def test_list_resource_classes_sorted(self):
        names = []
        for i in range(5):
            resource = utils.create_test_resource_class(
                context=self.context,
                uuid=uuidutils.generate_uuid(),
                name='class' + str(i))
            names.append(str(resource.name))
        res = dbapi.list_resource_classes(self.context, sort_key='name')
        res_names = [r.name for r in res]
        self.assertEqual(sorted(names), res_names)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_resource_classes,
                          self.context,
                          sort_key='foo') 
Example #21
Source File: test_compute_host.py    From zun with Apache License 2.0 5 votes vote down vote up
def test_destroy_compute_node_that_does_not_exist(self):
        self.assertRaises(exception.ComputeNodeNotFound,
                          dbapi.destroy_compute_node, self.context,
                          uuidutils.generate_uuid()) 
Example #22
Source File: test_container_action.py    From zun with Apache License 2.0 5 votes vote down vote up
def test_container_action_start(self):
        """Create a container action."""
        uuid = uuidutils.generate_uuid()
        action_values = self._create_action_values(uuid)
        action = dbapi.action_start(self.context, action_values)

        ignored_keys = self.IGNORED_FIELDS + ['finish_time']
        self._assertEqualObjects(action_values, action, ignored_keys)

        self._assertActionSaved(action, uuid) 
Example #23
Source File: test_compute_host.py    From zun with Apache License 2.0 5 votes vote down vote up
def test_list_compute_nodes(self):
        uuids = []
        for i in range(1, 6):
            node = utils.create_test_compute_node(
                uuid=uuidutils.generate_uuid(),
                rp_uuid=uuidutils.generate_uuid(),
                context=self.context,
                hostname='node' + str(i))
            uuids.append(str(node['uuid']))
        res = dbapi.list_compute_nodes(self.context)
        res_uuids = [r.uuid for r in res]
        self.assertEqual(sorted(uuids), sorted(res_uuids)) 
Example #24
Source File: test_compute_host.py    From zun with Apache License 2.0 5 votes vote down vote up
def test_get_compute_node_that_does_not_exist(self):
        self.assertRaises(exception.ComputeNodeNotFound,
                          dbapi.get_compute_node,
                          self.context,
                          uuidutils.generate_uuid()) 
Example #25
Source File: test_registry.py    From zun with Apache License 2.0 5 votes vote down vote up
def test_update_registry_not_found(self):
        registry_uuid = uuidutils.generate_uuid()
        new_name = 'new-name'
        self.assertRaises(exception.RegistryNotFound,
                          dbapi.update_registry, self.context,
                          registry_uuid, {'name': new_name}) 
Example #26
Source File: test_image.py    From zun with Apache License 2.0 5 votes vote down vote up
def test_get_image_that_does_not_exist(self):
        self.assertRaises(exception.ImageNotFound,
                          self.dbapi.get_image_by_id, self.context, 99)
        self.assertRaises(exception.ImageNotFound,
                          self.dbapi.get_image_by_uuid,
                          self.context,
                          uuidutils.generate_uuid()) 
Example #27
Source File: test_image.py    From zun with Apache License 2.0 5 votes vote down vote up
def test_list_images_sorted(self):
        uuids = []
        for i in range(5):
            image = utils.create_test_image(
                context=self.context, uuid=uuidutils.generate_uuid(),
                repo="testrepo" + str(i))
            uuids.append(str(image.uuid))
        res = self.dbapi.list_images(self.context, sort_key='uuid')
        res_uuids = [r.uuid for r in res]
        self.assertEqual(sorted(uuids), res_uuids)

        self.assertRaises(exception.InvalidParameterValue,
                          self.dbapi.list_images,
                          self.context,
                          sort_key='foo') 
Example #28
Source File: test_registry.py    From zun with Apache License 2.0 5 votes vote down vote up
def test_list_registries_with_list_filters(self):
        registry1 = utils.create_test_registry(
            name='registry-one',
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        registry2 = utils.create_test_registry(
            name='registry-two',
            uuid=uuidutils.generate_uuid(),
            context=self.context)

        res = dbapi.list_registries(
            self.context, filters={'name': ['registry-one', 'registry-two']})
        uuids = sorted([registry1.uuid, registry2.uuid])
        self.assertEqual(uuids, sorted([r.uuid for r in res])) 
Example #29
Source File: test_container.py    From zun with Apache License 2.0 5 votes vote down vote up
def test_list_containers(self):
        uuids = []
        for i in range(1, 6):
            container = utils.create_test_container(
                uuid=uuidutils.generate_uuid(),
                context=self.context,
                name='container' + str(i))
            uuids.append(str(container['uuid']))
        res = dbapi.list_containers(self.context, consts.TYPE_CONTAINER)
        res_uuids = [r.uuid for r in res]
        self.assertEqual(sorted(uuids), sorted(res_uuids)) 
Example #30
Source File: test_image.py    From zun with Apache License 2.0 5 votes vote down vote up
def test_update_image_not_found(self):
        image_uuid = uuidutils.generate_uuid()
        new_size = '2000'
        self.assertRaises(exception.ImageNotFound,
                          self.dbapi.update_image,
                          image_uuid, {'size': new_size})