Beispiel #1
0
    def test_is_public_string_variations(self):
        flavor_id_not_public = rand_int_id(start=1000)
        flavor_name_not_public = rand_name(self.flavor_name_prefix)
        flavor_id_public = rand_int_id(start=1000)
        flavor_name_public = rand_name(self.flavor_name_prefix)

        # Create a non public flavor
        resp, flavor = self.client.create_flavor(
            flavor_name_not_public, self.ram, self.vcpus, self.disk, flavor_id_not_public, is_public="False"
        )
        self.addCleanup(self.flavor_clean_up, flavor["id"])

        # Create a public flavor
        resp, flavor = self.client.create_flavor(
            flavor_name_public, self.ram, self.vcpus, self.disk, flavor_id_public, is_public="True"
        )
        self.addCleanup(self.flavor_clean_up, flavor["id"])

        def _flavor_lookup(flavors, flavor_name):
            for flavor in flavors:
                if flavor["name"] == flavor_name:
                    return flavor
            return None

        def _test_string_variations(variations, flavor_name):
            for string in variations:
                params = {"is_public": string}
                r, flavors = self.client.list_flavors_with_detail(params)
                self.assertEqual(r.status, 200)
                flavor = _flavor_lookup(flavors, flavor_name)
                self.assertNotEqual(flavor, None)

        _test_string_variations(["f", "false", "no", "0"], flavor_name_not_public)

        _test_string_variations(["t", "true", "yes", "1"], flavor_name_public)
 def _get_unused_flavor_id(self):
     flavor_id = data_utils.rand_int_id(start=1000)
     while True:
         try:
             resp, body = self.flavors_client.get_flavor_details(flavor_id)
         except exceptions.NotFound:
             break
         flavor_id = data_utils.rand_int_id(start=1000)
     return flavor_id
 def _get_unused_flavor_id(self):
     flavor_id = data_utils.rand_int_id(start=1000)
     while True:
         try:
             self.flavors_client.show_flavor(flavor_id)
         except lib_exc.NotFound:
             break
         flavor_id = data_utils.rand_int_id(start=1000)
     return flavor_id
Beispiel #4
0
 def populate_smoke_table(self, table_name, keycount, count_per_key):
     new_items = []
     for _ in range(keycount):
         forum = 'forum%s' % data_utils.rand_int_id()
         for i in range(count_per_key):
             item = self.build_smoke_item(forum,
                                          'subject%s' % i,
                                          data_utils.rand_name(),
                                          data_utils.rand_uuid(),
                                          str(data_utils.rand_int_id()))
             self.client.put_item(table_name, item)
             new_items.append(item)
     return new_items
Beispiel #5
0
    def test_get_flavor_details_for_deleted_flavor(self):
        # Delete a flavor and ensure it is not listed
        # Create a test flavor
        flavor_name = rand_name(self.flavor_name_prefix)
        new_flavor_id = rand_int_id(start=1000)

        resp, flavor = self.client.create_flavor(flavor_name,
                                                 self.ram,
                                                 self.vcpus,
                                                 self.disk,
                                                 new_flavor_id,
                                                 ephemeral=self.ephemeral,
                                                 swap=self.swap,
                                                 rxtx=self.rxtx)
        # Delete the flavor
        new_flavor_id = flavor['id']
        resp_delete, body = self.client.delete_flavor(new_flavor_id)
        self.assertEquals(200, resp.status)
        self.assertEquals(202, resp_delete.status)

        # Deleted flavors can be seen via detailed GET
        resp, flavor = self.client.get_flavor_details(new_flavor_id)
        self.assertEqual(resp.status, 200)
        self.assertEqual(flavor['name'], flavor_name)

        # Deleted flavors should not show up in a list however
        resp, flavors = self.client.list_flavors_with_detail()
        self.assertEqual(resp.status, 200)
        flag = True
        for flavor in flavors:
            if flavor['name'] == flavor_name:
                flag = False
        self.assertTrue(flag)
Beispiel #6
0
    def test_list_public_flavor_with_other_user(self):
        # Create a Flavor with public access.
        # Try to List/Get flavor with another user
        flavor_name = rand_name(self.flavor_name_prefix)
        new_flavor_id = rand_int_id(start=1000)

        try:
            # Create the flavor
            resp, flavor = self.client.create_flavor(
                flavor_name, self.ram, self.vcpus, self.disk, new_flavor_id, is_public="True"
            )
            flag = False
            self.new_client = self.flavors_client
            # Verify flavor is retrieved with new user
            resp, flavors = self.new_client.list_flavors_with_detail()
            self.assertEqual(resp.status, 200)
            for flavor in flavors:
                if flavor["name"] == flavor_name:
                    flag = True
            self.assertTrue(flag)
        finally:
            # Delete the flavor
            resp, body = self.client.delete_flavor(new_flavor_id)
            self.assertEqual(resp.status, 202)
            self.client.wait_for_resource_deletion(new_flavor_id)
Beispiel #7
0
    def test_add_flavor_access_duplicate(self):
        # Create a new flavor.
        flavor_name = data_utils.rand_name(self.flavor_name_prefix)
        new_flavor_id = data_utils.rand_int_id(start=1000)
        new_flavor = self.admin_flavors_client.create_flavor(
            name=flavor_name,
            ram=self.ram,
            vcpus=self.vcpus,
            disk=self.disk,
            id=new_flavor_id,
            is_public='False')['flavor']
        self.addCleanup(self.admin_flavors_client.delete_flavor,
                        new_flavor['id'])

        # Add flavor access to a tenant.
        self.admin_flavors_client.add_flavor_access(new_flavor['id'],
                                                    self.tenant_id)
        self.addCleanup(self.admin_flavors_client.remove_flavor_access,
                        new_flavor['id'], self.tenant_id)

        # An exception should be raised when adding flavor access to the same
        # tenant
        self.assertRaises(lib_exc.Conflict,
                          self.admin_flavors_client.add_flavor_access,
                          new_flavor['id'], self.tenant_id)
Beispiel #8
0
    def test_create_flavor_verify_entry_in_list_details(self):
        # Create a flavor and ensure it's details are listed
        # This operation requires the user to have 'admin' role
        flavor_name = rand_name(self.flavor_name_prefix)
        new_flavor_id = rand_int_id(start=1000)

        try:
            #Create the flavor
            resp, flavor = self.client.create_flavor(flavor_name,
                                                     self.ram, self.vcpus,
                                                     self.disk,
                                                     new_flavor_id,
                                                     ephemeral=self.ephemeral,
                                                     swap=self.swap,
                                                     rxtx=self.rxtx)
            flag = False
            #Verify flavor is retrieved
            resp, flavors = self.client.list_flavors_with_detail()
            self.assertEqual(resp.status, 200)
            for flavor in flavors:
                if flavor['name'] == flavor_name:
                    flag = True
            self.assertTrue(flag)

        finally:
            #Delete the flavor
            resp, body = self.client.delete_flavor(new_flavor_id)
            self.assertEqual(resp.status, 202)
            self.client.wait_for_resource_deletion(new_flavor_id)
Beispiel #9
0
    def test_flavor_not_public_verify_entry_not_in_list_details(self):
        #Create a flavor with os-flavor-access:is_public false should not
        #be present in list_details.
        #This operation requires the user to have 'admin' role
        flavor_name = rand_name(self.flavor_name_prefix)
        new_flavor_id = rand_int_id(start=1000)

        try:
            #Create the flavor
            resp, flavor = self.client.create_flavor(flavor_name,
                                                     self.ram, self.vcpus,
                                                     self.disk,
                                                     new_flavor_id,
                                                     is_public="False")
            flag = False
            #Verify flavor is retrieved
            resp, flavors = self.client.list_flavors_with_detail()
            self.assertEqual(resp.status, 200)
            for flavor in flavors:
                if flavor['name'] == flavor_name:
                    flag = True
            self.assertFalse(flag)
        finally:
            #Delete the flavor
            resp, body = self.client.delete_flavor(new_flavor_id)
            self.assertEqual(resp.status, 202)
Beispiel #10
0
 def test_set_and_get_queue_metadata(self):
     # Retrieve random queue
     queue_name = self.queues[data_utils.rand_int_id(
         0,
         len(self.queues) - 1)]
     # Check the Queue has no metadata
     resp, body = self.get_queue_metadata(queue_name)
     self.assertEqual('200', resp['status'])
     self.assertThat(body, matchers.HasLength(0))
     # Create metadata
     key3 = [0, 1, 2, 3, 4]
     key2 = data_utils.rand_name('value')
     req_body1 = dict()
     req_body1[data_utils.rand_name('key3')] = key3
     req_body1[data_utils.rand_name('key2')] = key2
     req_body = dict()
     req_body[data_utils.rand_name('key1')] = req_body1
     # Set Queue Metadata
     resp, body = self.set_queue_metadata(queue_name, req_body)
     self.assertEqual('204', resp['status'])
     self.assertEqual('', body)
     # Get Queue Metadata
     resp, body = self.get_queue_metadata(queue_name)
     self.assertEqual('200', resp['status'])
     self.assertThat(body, matchers.Equals(req_body))
    def test_flavor_access_add_remove(self):
        # Test to add and remove flavor access to a given tenant.
        flavor_name = data_utils.rand_name(self.flavor_name_prefix)
        new_flavor_id = data_utils.rand_int_id(start=1000)
        new_flavor = self.client.create_flavor(name=flavor_name,
                                               ram=self.ram, vcpus=self.vcpus,
                                               disk=self.disk,
                                               id=new_flavor_id,
                                               is_public='False')['flavor']
        self.addCleanup(self.client.delete_flavor, new_flavor['id'])
        # Add flavor access to a tenant.
        resp_body = {
            "tenant_id": str(self.tenant_id),
            "flavor_id": str(new_flavor['id']),
        }
        add_body = (self.client.add_flavor_access(new_flavor['id'],
                                                  self.tenant_id)
                    ['flavor_access'])
        self.assertIn(resp_body, add_body)

        # The flavor is present in list.
        flavors = self.flavors_client.list_flavors(detail=True)['flavors']
        self.assertIn(new_flavor['id'], map(lambda x: x['id'], flavors))

        # Remove flavor access from a tenant.
        remove_body = (self.client.remove_flavor_access(new_flavor['id'],
                                                        self.tenant_id)
                       ['flavor_access'])
        self.assertNotIn(resp_body, remove_body)

        # The flavor is not present in list.
        flavors = self.flavors_client.list_flavors(detail=True)['flavors']
        self.assertNotIn(new_flavor['id'], map(lambda x: x['id'], flavors))
Beispiel #12
0
 def test_create_flavor_with_int_id(self):
     flavor_id = data_utils.rand_int_id(start=1000)
     new_flavor_id = self.create_flavor(ram=self.ram,
                                        vcpus=self.vcpus,
                                        disk=self.disk,
                                        id=flavor_id)['id']
     self.assertEqual(new_flavor_id, str(flavor_id))
Beispiel #13
0
    def test_create_flavor(self):
        # Create a flavor and ensure it is listed
        # This operation requires the user to have 'admin' role
        flavor_name = rand_name(self.flavor_name_prefix)
        new_flavor_id = rand_int_id(start=1000)

        # Create the flavor
        resp, flavor = self.client.create_flavor(flavor_name,
                                                 self.ram, self.vcpus,
                                                 self.disk,
                                                 new_flavor_id,
                                                 ephemeral=self.ephemeral,
                                                 swap=self.swap,
                                                 rxtx=self.rxtx)
        self.addCleanup(self.flavor_clean_up, flavor['id'])
        self.assertEqual(200, resp.status)
        self.assertEqual(flavor['name'], flavor_name)
        self.assertEqual(flavor['vcpus'], self.vcpus)
        self.assertEqual(flavor['disk'], self.disk)
        self.assertEqual(flavor['ram'], self.ram)
        self.assertEqual(int(flavor['id']), new_flavor_id)
        self.assertEqual(flavor['swap'], self.swap)
        self.assertEqual(flavor['rxtx_factor'], self.rxtx)
        self.assertEqual(flavor['OS-FLV-EXT-DATA:ephemeral'],
                         self.ephemeral)
        self.assertEqual(flavor['os-flavor-access:is_public'], True)

        # Verify flavor is retrieved
        resp, flavor = self.client.get_flavor_details(new_flavor_id)
        self.assertEqual(resp.status, 200)
        self.assertEqual(flavor['name'], flavor_name)
 def test_volume_list_details_by_name(self):
     volume = self.volume_list[data_utils.rand_int_id(0, 2)]
     params = {self.name: volume[self.name]}
     _, fetched_vol = self.client.list_volumes_with_detail(params)
     self.assertEqual(1, len(fetched_vol), str(fetched_vol))
     self.assertEqual(fetched_vol[0][self.name],
                      volume[self.name])
Beispiel #15
0
 def test_volume_list_details_by_name(self):
     volume = self.volume_list[data_utils.rand_int_id(0, 2)]
     params = {'name': volume['name']}
     resp, fetched_vol = self.client.list_volumes_with_detail(params)
     self.assertEqual(200, resp.status)
     self.assertEqual(1, len(fetched_vol), str(fetched_vol))
     self.assertEqual(fetched_vol[0]['name'], volume['name'])
Beispiel #16
0
 def test_volume_list_with_detail_param_display_name_and_status(self):
     # Test to list volume when name and status param is given
     volume = self.volume_list[data_utils.rand_int_id(0, 2)]
     params = {'name': volume['name'], 'status': 'available'}
     self._list_by_param_value_and_assert(params,
                                          expected_list=[volume],
                                          with_detail=True)
Beispiel #17
0
    def test_get_flavor_details_for_deleted_flavor(self):
        # Delete a flavor and ensure it is not listed
        # Create a test flavor
        flavor_name = rand_name(self.flavor_name_prefix)
        new_flavor_id = rand_int_id(start=1000)

        resp, flavor = self.client.create_flavor(flavor_name,
                                                 self.ram,
                                                 self.vcpus, self.disk,
                                                 new_flavor_id,
                                                 ephemeral=self.ephemeral,
                                                 swap=self.swap,
                                                 rxtx=self.rxtx)
        # Delete the flavor
        new_flavor_id = flavor['id']
        resp_delete, body = self.client.delete_flavor(new_flavor_id)
        self.assertEquals(200, resp.status)
        self.assertEquals(202, resp_delete.status)

        # Deleted flavors can be seen via detailed GET
        resp, flavor = self.client.get_flavor_details(new_flavor_id)
        self.assertEqual(resp.status, 200)
        self.assertEqual(flavor['name'], flavor_name)

        # Deleted flavors should not show up in a list however
        resp, flavors = self.client.list_flavors_with_detail()
        self.assertEqual(resp.status, 200)
        flag = True
        for flavor in flavors:
            if flavor['name'] == flavor_name:
                flag = False
        self.assertTrue(flag)
Beispiel #18
0
 def test_volume_list_details_by_name(self):
     volume = self.volume_list[data_utils.rand_int_id(0, 2)]
     params = {'name': volume['name']}
     resp, fetched_vol = self.client.list_volumes_with_detail(params)
     self.assertEqual(200, resp.status)
     self.assertEqual(1, len(fetched_vol), str(fetched_vol))
     self.assertEqual(fetched_vol[0]['name'], volume['name'])
 def test_delete_security_group_rule_with_non_existent_id(self):
     # Negative test: Deletion of Security Group rule should be FAIL
     # with non existent id
     non_existent_rule_id = data_utils.rand_int_id(start=999)
     self.assertRaises(exceptions.NotFound,
                       self.client.delete_security_group_rule,
                       non_existent_rule_id)
Beispiel #20
0
 def test_volume_list_details_by_name(self):
     volume = self.volume_list[data_utils.rand_int_id(0, 2)]
     params = {self.name: volume[self.name]}
     fetched_vol = self.volumes_client.list_volumes(
         detail=True, params=params)['volumes']
     self.assertEqual(1, len(fetched_vol), str(fetched_vol))
     self.assertEqual(fetched_vol[0][self.name], volume[self.name])
Beispiel #21
0
    def test_list_non_public_flavor(self):
        # Create a flavor with os-flavor-access:is_public false should
        # be present in list_details.
        # This operation requires the user to have 'admin' role
        flavor_name = data_utils.rand_name(self.flavor_name_prefix)
        new_flavor_id = data_utils.rand_int_id(start=1000)

        # Create the flavor
        resp, flavor = self.client.create_flavor(flavor_name,
                                                 self.ram, self.vcpus,
                                                 self.disk,
                                                 new_flavor_id,
                                                 is_public="False")
        self.addCleanup(self.flavor_clean_up, flavor['id'])
        # Verify flavor is retrieved
        flag = False
        resp, flavors = self.client.list_flavors_with_detail()
        self.assertEqual(resp.status, 200)
        for flavor in flavors:
            if flavor['name'] == flavor_name:
                flag = True
        self.assertTrue(flag)

        # Verify flavor is not retrieved with other user
        flag = False
        resp, flavors = self.user_client.list_flavors_with_detail()
        self.assertEqual(resp.status, 200)
        for flavor in flavors:
            if flavor['name'] == flavor_name:
                flag = True
        self.assertFalse(flag)
Beispiel #22
0
    def test_create_flavor_verify_entry_in_list_details(self):
        # Create a flavor and ensure it's details are listed
        # This operation requires the user to have 'admin' role
        flavor_name = rand_name(self.flavor_name_prefix)
        new_flavor_id = rand_int_id(start=1000)

        # Create the flavor
        resp, flavor = self.client.create_flavor(
            flavor_name,
            self.ram,
            self.vcpus,
            self.disk,
            new_flavor_id,
            ephemeral=self.ephemeral,
            swap=self.swap,
            rxtx=self.rxtx,
        )
        self.addCleanup(self.flavor_clean_up, flavor["id"])
        flag = False
        # Verify flavor is retrieved
        resp, flavors = self.client.list_flavors_with_detail()
        self.assertEqual(resp.status, 200)
        for flavor in flavors:
            if flavor["name"] == flavor_name:
                flag = True
        self.assertTrue(flag)
 def test_volume_list_by_name(self):
     volume = self.volume_list[data_utils.rand_int_id(0, 2)]
     params = {self.name: volume[self.name]}
     resp, fetched_vol = self.client.list_volumes(params)
     self.assertEqual(200, resp.status)
     self.assertEqual(1, len(fetched_vol), str(fetched_vol))
     self.assertEqual(fetched_vol[0][self.name], volume[self.name])
Beispiel #24
0
 def test_volume_list_with_detail_param_display_name_and_status(self):
     # Test to list volume when name and status param is given
     volume = self.volume_list[data_utils.rand_int_id(0, 2)]
     params = {'name': volume['name'],
               'status': 'available'}
     self._list_by_param_value_and_assert(params, expected_list=[volume],
                                          with_detail=True)
Beispiel #25
0
    def test_list_non_public_flavor(self):
        # Create a flavor with os-flavor-access:is_public false.
        # The flavor should not be present in list_details as the
        # tenant is not automatically added access list.
        # This operation requires the user to have 'admin' role
        flavor_name = data_utils.rand_name(self.flavor_name_prefix)
        new_flavor_id = data_utils.rand_int_id(start=1000)

        # Create the flavor
        flavor = self.client.create_flavor(name=flavor_name,
                                           ram=self.ram,
                                           vcpus=self.vcpus,
                                           disk=self.disk,
                                           id=new_flavor_id,
                                           is_public="False")
        self.addCleanup(self.flavor_clean_up, flavor['id'])
        # Verify flavor is retrieved
        flag = False
        flavors = self.client.list_flavors(detail=True)
        for flavor in flavors:
            if flavor['name'] == flavor_name:
                flag = True
        self.assertFalse(flag)

        # Verify flavor is not retrieved with other user
        flag = False
        flavors = self.user_client.list_flavors(detail=True)
        for flavor in flavors:
            if flavor['name'] == flavor_name:
                flag = True
        self.assertFalse(flag)
Beispiel #26
0
    def _post_and_claim_messages(self, queue_name, repeat=1):
        # Post Messages
        message_body = self.generate_message_body(repeat=repeat)
        self.client.post_messages(queue_name=self.queue_name,
                                  rbody=message_body)

        # Post Claim
        claim_ttl = data_utils.rand_int_id(start=60,
                                           end=CONF.queuing.max_claim_ttl)
        claim_grace = data_utils.rand_int_id(start=60,
                                             end=CONF.queuing.max_claim_grace)
        claim_body = {"ttl": claim_ttl, "grace": claim_grace}
        resp, body = self.client.post_claims(queue_name=self.queue_name,
                                             rbody=claim_body)

        return resp, body
    def setUpClass(cls):
        super(FlavorsExtraSpecsNegativeTestJSON, cls).setUpClass()
        if not test.is_extension_enabled('FlavorExtraData', 'compute'):
            msg = "FlavorExtraData extension not enabled."
            raise cls.skipException(msg)

        cls.client = cls.os_adm.flavors_client
        flavor_name = data_utils.rand_name('test_flavor')
        ram = 512
        vcpus = 1
        disk = 10
        ephemeral = 10
        cls.new_flavor_id = data_utils.rand_int_id(start=1000)
        swap = 1024
        rxtx = 1
        # Create a flavor
        resp, cls.flavor = cls.client.create_flavor(
            flavor_name,
            ram,
            vcpus,
            disk,
            cls.new_flavor_id,
            ephemeral=ephemeral,
            swap=swap,
            rxtx=rxtx)
 def test_delete_security_group_rule_with_non_existent_id(self):
     # Negative test: Deletion of Security Group rule should be FAIL
     # with non existent id
     non_existent_rule_id = data_utils.rand_int_id(start=999)
     self.assertRaises(exceptions.NotFound,
                       self.client.delete_security_group_rule,
                       non_existent_rule_id)
Beispiel #29
0
    def test_flavor_access_add_remove(self):
        # Test to add and remove flavor access to a given tenant.
        flavor_name = data_utils.rand_name(self.flavor_name_prefix)
        new_flavor_id = data_utils.rand_int_id(start=1000)
        resp, new_flavor = self.client.create_flavor(flavor_name,
                                                     self.ram, self.vcpus,
                                                     self.disk,
                                                     new_flavor_id,
                                                     is_public='False')
        self.addCleanup(self.client.delete_flavor, new_flavor['id'])
        # Add flavor access to a tenant.
        resp_body = {
            "tenant_id": str(self.tenant_id),
            "flavor_id": str(new_flavor['id']),
        }
        add_resp, add_body = \
            self.client.add_flavor_access(new_flavor['id'], self.tenant_id)
        self.assertEqual(add_resp.status, 200)
        self.assertIn(resp_body, add_body)

        # The flavor is present in list.
        resp, flavors = self.flavors_client.list_flavors_with_detail()
        self.assertEqual(resp.status, 200)
        self.assertIn(new_flavor['id'], map(lambda x: x['id'], flavors))

        # Remove flavor access from a tenant.
        remove_resp, remove_body = \
            self.client.remove_flavor_access(new_flavor['id'], self.tenant_id)
        self.assertEqual(remove_resp.status, 200)
        self.assertNotIn(resp_body, remove_body)

        # The flavor is not present in list.
        resp, flavors = self.flavors_client.list_flavors_with_detail()
        self.assertEqual(resp.status, 200)
        self.assertNotIn(new_flavor['id'], map(lambda x: x['id'], flavors))
 def test_volume_list_by_name(self):
     volume = self.volume_list[data_utils.rand_int_id(0, 2)]
     params = {self.name: volume[self.name]}
     fetched_vol = self.client.list_volumes(params=params)['volumes']
     self.assertEqual(1, len(fetched_vol), str(fetched_vol))
     self.assertEqual(fetched_vol[0][self.name],
                      volume[self.name])
Beispiel #31
0
    def test_create_flavor_verify_entry_in_list_details(self):
        # Create a flavor and ensure it's details are listed
        # This operation requires the user to have 'admin' role
        flavor_name = data_utils.rand_name(self.flavor_name_prefix)
        new_flavor_id = data_utils.rand_int_id(start=1000)

        # Create the flavor
        flavor = self.client.create_flavor(
            name=flavor_name,
            ram=self.ram,
            vcpus=self.vcpus,
            disk=self.disk,
            id=new_flavor_id,
            ephemeral=self.ephemeral,
            swap=self.swap,
            rxtx_factor=self.rxtx,
        )["flavor"]
        self.addCleanup(self.flavor_clean_up, flavor["id"])
        flag = False
        # Verify flavor is retrieved
        flavors = self.client.list_flavors(detail=True)["flavors"]
        for flavor in flavors:
            if flavor["name"] == flavor_name:
                flag = True
        self.assertTrue(flag)
Beispiel #32
0
    def test_flavor_access_add_remove(self):
        # Test to add and remove flavor access to a given tenant.
        flavor_name = data_utils.rand_name(self.flavor_name_prefix)
        new_flavor_id = data_utils.rand_int_id(start=1000)
        new_flavor = self.client.create_flavor(name=flavor_name,
                                               ram=self.ram,
                                               vcpus=self.vcpus,
                                               disk=self.disk,
                                               id=new_flavor_id,
                                               is_public='False')['flavor']
        self.addCleanup(self.client.delete_flavor, new_flavor['id'])
        # Add flavor access to a tenant.
        resp_body = {
            "tenant_id": str(self.tenant_id),
            "flavor_id": str(new_flavor['id']),
        }
        add_body = (self.client.add_flavor_access(
            new_flavor['id'], self.tenant_id)['flavor_access'])
        self.assertIn(resp_body, add_body)

        # The flavor is present in list.
        flavors = self.flavors_client.list_flavors(detail=True)['flavors']
        self.assertIn(new_flavor['id'], map(lambda x: x['id'], flavors))

        # Remove flavor access from a tenant.
        remove_body = (self.client.remove_flavor_access(
            new_flavor['id'], self.tenant_id)['flavor_access'])
        self.assertNotIn(resp_body, remove_body)

        # The flavor is not present in list.
        flavors = self.flavors_client.list_flavors(detail=True)['flavors']
        self.assertNotIn(new_flavor['id'], map(lambda x: x['id'], flavors))
Beispiel #33
0
    def test_list_non_public_flavor(self):
        # Create a flavor with os-flavor-access:is_public false should
        # be present in list_details.
        # This operation requires the user to have 'admin' role
        flavor_name = data_utils.rand_name(self.flavor_name_prefix)
        new_flavor_id = data_utils.rand_int_id(start=1000)

        # Create the flavor
        resp, flavor = self.client.create_flavor(flavor_name,
                                                 self.ram, self.vcpus,
                                                 self.disk,
                                                 new_flavor_id,
                                                 is_public="False")
        self.addCleanup(self.flavor_clean_up, flavor['id'])
        # Verify flavor is retrieved
        flag = False
        resp, flavors = self.client.list_flavors_with_detail()
        self.assertEqual(resp.status, 200)
        for flavor in flavors:
            if flavor['name'] == flavor_name:
                flag = True
        self.assertTrue(flag)

        # Verify flavor is not retrieved with other user
        flag = False
        resp, flavors = self.user_client.list_flavors_with_detail()
        self.assertEqual(resp.status, 200)
        for flavor in flavors:
            if flavor['name'] == flavor_name:
                flag = True
        self.assertFalse(flag)
    def test_flavor_access_add_remove(self):
        # Test to add and remove flavor access to a given tenant.
        flavor_name = data_utils.rand_name(self.flavor_name_prefix)
        new_flavor_id = data_utils.rand_int_id(start=1000)
        resp, new_flavor = self.client.create_flavor(flavor_name,
                                                     self.ram, self.vcpus,
                                                     self.disk,
                                                     new_flavor_id,
                                                     is_public='False')
        self.addCleanup(self.client.delete_flavor, new_flavor['id'])
        # Add flavor access to a tenant.
        resp_body = {
            "tenant_id": str(self.tenant_id),
            "flavor_id": str(new_flavor['id']),
        }
        add_resp, add_body = \
            self.client.add_flavor_access(new_flavor['id'], self.tenant_id)
        self.assertEqual(add_resp.status, 200)
        self.assertIn(resp_body, add_body)

        # The flavor is present in list.
        resp, flavors = self.flavors_client.list_flavors_with_detail()
        self.assertEqual(resp.status, 200)
        self.assertIn(new_flavor['id'], map(lambda x: x['id'], flavors))

        # Remove flavor access from a tenant.
        remove_resp, remove_body = \
            self.client.remove_flavor_access(new_flavor['id'], self.tenant_id)
        self.assertEqual(remove_resp.status, 200)
        self.assertNotIn(resp_body, remove_body)

        # The flavor is not present in list.
        resp, flavors = self.flavors_client.list_flavors_with_detail()
        self.assertEqual(resp.status, 200)
        self.assertNotIn(new_flavor['id'], map(lambda x: x['id'], flavors))
Beispiel #35
0
 def test_volume_list_details_by_name(self):
     volume = self.volume_list[data_utils.rand_int_id(0, 2)]
     params = {self.name: volume[self.name]}
     _, fetched_vol = self.client.list_volumes_with_detail(params)
     self.assertEqual(1, len(fetched_vol), str(fetched_vol))
     self.assertEqual(fetched_vol[0][self.name],
                      volume[self.name])
Beispiel #36
0
    def test_list_non_public_flavor(self):
        # Create a flavor with os-flavor-access:is_public false.
        # The flavor should not be present in list_details as the
        # tenant is not automatically added access list.
        # This operation requires the user to have 'admin' role
        flavor_name = data_utils.rand_name(self.flavor_name_prefix)
        new_flavor_id = data_utils.rand_int_id(start=1000)

        # Create the flavor
        flavor = self.client.create_flavor(name=flavor_name,
                                           ram=self.ram, vcpus=self.vcpus,
                                           disk=self.disk,
                                           id=new_flavor_id,
                                           is_public="False")
        self.addCleanup(self.flavor_clean_up, flavor['id'])
        # Verify flavor is retrieved
        flag = False
        flavors = self.client.list_flavors(detail=True)
        for flavor in flavors:
            if flavor['name'] == flavor_name:
                flag = True
        self.assertFalse(flag)

        # Verify flavor is not retrieved with other user
        flag = False
        flavors = self.user_client.list_flavors(detail=True)
        for flavor in flavors:
            if flavor['name'] == flavor_name:
                flag = True
        self.assertFalse(flag)
Beispiel #37
0
    def _post_and_claim_messages(self, queue_name, repeat=1):
        # Post Messages
        message_body = self.generate_message_body(repeat=repeat)
        self.client.post_messages(queue_name=self.queue_name,
                                  rbody=message_body)

        # Post Claim
        claim_ttl = data_utils.rand_int_id(start=60,
                                           end=CONF.queuing.max_claim_ttl)
        claim_grace = data_utils.rand_int_id(start=60,
                                             end=CONF.queuing.max_claim_grace)
        claim_body = {"ttl": claim_ttl, "grace": claim_grace}
        resp, body = self.client.post_claims(queue_name=self.queue_name,
                                             rbody=claim_body)

        return resp, body
Beispiel #38
0
    def test_is_public_string_variations(self):
        try:
            flavor_id_not_public = rand_int_id(start=1000)
            flavor_name_not_public = rand_name(self.flavor_name_prefix)
            flavor_id_public = rand_int_id(start=1000)
            flavor_name_public = rand_name(self.flavor_name_prefix)

            # Create a non public flavor
            resp, flavor = self.client.create_flavor(flavor_name_not_public,
                                                     self.ram, self.vcpus,
                                                     self.disk,
                                                     flavor_id_not_public,
                                                     is_public="False")

            # Create a public flavor
            resp, flavor = self.client.create_flavor(flavor_name_public,
                                                     self.ram, self.vcpus,
                                                     self.disk,
                                                     flavor_id_public,
                                                     is_public="True")

            def _flavor_lookup(flavors, flavor_name):
                for flavor in flavors:
                    if flavor['name'] == flavor_name:
                        return flavor
                return None

            def _test_string_variations(variations, flavor_name):
                for string in variations:
                    params = {'is_public': string}
                    r, flavors = self.client.list_flavors_with_detail(params)
                    self.assertEqual(r.status, 200)
                    flavor = _flavor_lookup(flavors, flavor_name)
                    self.assertNotEqual(flavor, None)

            _test_string_variations(['f', 'false', 'no', '0'],
                                    flavor_name_not_public)

            _test_string_variations(['t', 'true', 'yes', '1'],
                                    flavor_name_public)

        finally:
            # Delete flavors
            for flavor_id in [flavor_id_not_public, flavor_id_public]:
                resp, body = self.client.delete_flavor(flavor_id)
                self.assertEqual(resp.status, 202)
                self.client.wait_for_resource_deletion(flavor_id)
Beispiel #39
0
    def test_create_flavor_using_invalid_vcpus(self):
        flavor_name = rand_name(self.flavor_name_prefix)
        new_flavor_id = rand_int_id(start=1000)

        self.assertRaises(exceptions.BadRequest,
                          self.client.create_flavor,
                          flavor_name, self.ram, 0,
                          self.disk, new_flavor_id)
Beispiel #40
0
 def test_volume_list_by_name(self):
     volume = self.volume_list[rand_int_id(0, 2)]
     params = {'display_name': volume['display_name']}
     resp, fetched_vol = self.client.list_volumes(params)
     self.assertEqual(200, resp.status)
     self.assertEqual(1, len(fetched_vol), str(fetched_vol))
     self.assertEqual(fetched_vol[0]['display_name'],
                      volume['display_name'])
Beispiel #41
0
 def test_volumes_list_by_availability_zone(self):
     volume = self.volume_list[data_utils.rand_int_id(0, 2)]
     zone = volume['availability_zone']
     params = {'availability_zone': zone}
     _, fetched_list = self.client.list_volumes(params)
     self._list_by_param_value_and_assert(params)
     self.assertVolumesIn(fetched_list, self.volume_list,
                          fields=self.VOLUME_FIELDS)
 def test_volume_list_param_display_name_and_status(self):
     # Test to list volume when display name and status param is given
     volume = self.volume_list[data_utils.rand_int_id(0, 2)]
     params = {
         'display_name': volume['display_name'],
         'status': 'available'
     }
     self._list_by_param_value_and_assert(params)
 def test_volumes_list_details_by_availability_zone(self):
     volume = self.volume_list[data_utils.rand_int_id(0, 2)]
     zone = volume['availability_zone']
     params = {'availability_zone': zone}
     _, fetched_list = self.client.list_volumes_with_detail(params)
     for volume in fetched_list:
         self.assertEqual(zone, volume['availability_zone'])
     self.assertVolumesIn(fetched_list, self.volume_list)
 def test_volumes_list_by_availability_zone(self):
     volume = self.volume_list[data_utils.rand_int_id(0, 2)]
     zone = volume['availability_zone']
     params = {'availability_zone': zone}
     fetched_list = self.client.list_volumes(params=params)['volumes']
     self._list_by_param_value_and_assert(params)
     self.assertVolumesIn(fetched_list, self.volume_list,
                          fields=self.VOLUME_FIELDS)
Beispiel #45
0
 def test_volume_list_by_name(self):
     volume = self.volume_list[rand_int_id(0, 2)]
     params = {'display_name': volume['display_name']}
     resp, fetched_vol = self.client.list_volumes(params)
     self.assertEqual(200, resp.status)
     self.assertEqual(1, len(fetched_vol), str(fetched_vol))
     self.assertEqual(fetched_vol[0]['display_name'],
                      volume['display_name'])
 def test_volumes_list_details_by_availability_zone(self):
     volume = self.volume_list[data_utils.rand_int_id(0, 2)]
     zone = volume['availability_zone']
     params = {'availability_zone': zone}
     _, fetched_list = self.client.list_volumes_with_detail(params)
     for volume in fetched_list:
         self.assertEqual(zone, volume['availability_zone'])
     self.assertVolumesIn(fetched_list, self.volume_list)
    def test_create_flavor_using_invalid_ram(self):
        flavor_name = data_utils.rand_name(self.flavor_name_prefix)
        new_flavor_id = data_utils.rand_int_id(start=1000)

        self.assertRaises(exceptions.BadRequest,
                          self.client.create_flavor,
                          flavor_name, -1, self.vcpus,
                          self.disk, new_flavor_id)
 def test_flavor_access_list_with_public_flavor(self):
     # Test to list flavor access with exceptions by querying public flavor
     flavor_name = data_utils.rand_name(self.flavor_name_prefix)
     new_flavor_id = data_utils.rand_int_id(start=1000)
     new_flavor = self.client.create_flavor(
         flavor_name, self.ram, self.vcpus, self.disk, new_flavor_id, is_public="True"
     )
     self.addCleanup(self.client.delete_flavor, new_flavor["id"])
     self.assertRaises(exceptions.NotFound, self.client.list_flavor_access, new_flavor_id)
Beispiel #49
0
    def test_create_flavor_as_user(self):
        flavor_name = rand_name(self.flavor_name_prefix)
        new_flavor_id = rand_int_id(start=1000)

        self.assertRaises(exceptions.Unauthorized,
                          self.user_client.create_flavor,
                          flavor_name, self.ram, self.vcpus, self.disk,
                          new_flavor_id, ephemeral=self.ephemeral,
                          swap=self.swap, rxtx=self.rxtx)
Beispiel #50
0
 def test_volumes_list_by_availability_zone(self):
     volume = self.volume_list[rand_int_id(0, 2)]
     zone = volume['availability_zone']
     params = {'availability_zone': zone}
     resp, fetched_list = self.client.list_volumes(params)
     self.assertEqual(200, resp.status)
     for volume in fetched_list:
         self.assertEqual(zone, volume['availability_zone'])
     self.assertVolumesIn(fetched_list, self.volume_list)
Beispiel #51
0
    def test_create_flavor_as_user(self):
        flavor_name = rand_name(self.flavor_name_prefix)
        new_flavor_id = rand_int_id(start=1000)

        self.assertRaises(exceptions.Unauthorized,
                          self.user_client.create_flavor,
                          flavor_name, self.ram, self.vcpus, self.disk,
                          new_flavor_id, ephemeral=self.ephemeral,
                          swap=self.swap, rxtx=self.rxtx)
    def test_list_container_contents_with_limit(self):
        # get container contents list using limit param
        container_name = self.create_container()
        object_name, _ = self.create_object(container_name)

        params = {'limit': data_utils.rand_int_id(1, 10000)}
        resp, object_list = self.container_client.list_container_contents(
            container_name, params=params)
        self.assertHeaders(resp, 'Container', 'GET')
        self.assertEqual([object_name], object_list)
Beispiel #53
0
    def test_create_flavor_using_string_ram(self):
        new_flavor_id = data_utils.rand_int_id(start=1000)

        ram = "1024"
        flavor = self.create_flavor(ram=ram,
                                    vcpus=self.vcpus,
                                    disk=self.disk,
                                    id=new_flavor_id)
        self.assertEqual(flavor['ram'], int(ram))
        self.assertEqual(int(flavor['id']), new_flavor_id)
Beispiel #54
0
 def test_get_nonexistent_floating_ip_details(self):
     # Negative test:Should not be able to GET the details
     # of non-existent floating IP
     # Creating a non-existent floatingIP id
     if CONF.service_available.neutron:
         non_exist_id = str(uuid.uuid4())
     else:
         non_exist_id = data_utils.rand_int_id(start=999)
     self.assertRaises(exceptions.NotFound,
                       self.client.get_floating_ip_details, non_exist_id)
Beispiel #55
0
    def test_is_public_string_variations(self):
        flavor_id_not_public = data_utils.rand_int_id(start=1000)
        flavor_name_not_public = data_utils.rand_name(self.flavor_name_prefix)
        flavor_id_public = data_utils.rand_int_id(start=1000)
        flavor_name_public = data_utils.rand_name(self.flavor_name_prefix)

        # Create a non public flavor
        flavor = self.client.create_flavor(name=flavor_name_not_public,
                                           ram=self.ram,
                                           vcpus=self.vcpus,
                                           disk=self.disk,
                                           id=flavor_id_not_public,
                                           is_public="False")['flavor']
        self.addCleanup(self.flavor_clean_up, flavor['id'])

        # Create a public flavor
        flavor = self.client.create_flavor(name=flavor_name_public,
                                           ram=self.ram,
                                           vcpus=self.vcpus,
                                           disk=self.disk,
                                           id=flavor_id_public,
                                           is_public="True")['flavor']
        self.addCleanup(self.flavor_clean_up, flavor['id'])

        def _flavor_lookup(flavors, flavor_name):
            for flavor in flavors:
                if flavor['name'] == flavor_name:
                    return flavor
            return None

        def _test_string_variations(variations, flavor_name):
            for string in variations:
                params = {'is_public': string}
                flavors = (self.client.list_flavors(detail=True,
                                                    **params)['flavors'])
                flavor = _flavor_lookup(flavors, flavor_name)
                self.assertIsNotNone(flavor)

        _test_string_variations(['f', 'false', 'no', '0'],
                                flavor_name_not_public)

        _test_string_variations(['t', 'true', 'yes', '1'], flavor_name_public)
Beispiel #56
0
    def test_is_public_string_variations(self):
        flavor_id_not_public = rand_int_id(start=1000)
        flavor_name_not_public = rand_name(self.flavor_name_prefix)
        flavor_id_public = rand_int_id(start=1000)
        flavor_name_public = rand_name(self.flavor_name_prefix)

        # Create a non public flavor
        resp, flavor = self.client.create_flavor(flavor_name_not_public,
                                                 self.ram,
                                                 self.vcpus,
                                                 self.disk,
                                                 flavor_id_not_public,
                                                 is_public="False")
        self.addCleanup(self.flavor_clean_up, flavor['id'])

        # Create a public flavor
        resp, flavor = self.client.create_flavor(flavor_name_public,
                                                 self.ram,
                                                 self.vcpus,
                                                 self.disk,
                                                 flavor_id_public,
                                                 is_public="True")
        self.addCleanup(self.flavor_clean_up, flavor['id'])

        def _flavor_lookup(flavors, flavor_name):
            for flavor in flavors:
                if flavor['name'] == flavor_name:
                    return flavor
            return None

        def _test_string_variations(variations, flavor_name):
            for string in variations:
                params = {'is_public': string}
                r, flavors = self.client.list_flavors_with_detail(params)
                self.assertEqual(r.status, 200)
                flavor = _flavor_lookup(flavors, flavor_name)
                self.assertIsNotNone(flavor)

        _test_string_variations(['f', 'false', 'no', '0'],
                                flavor_name_not_public)

        _test_string_variations(['t', 'true', 'yes', '1'], flavor_name_public)
    def test_list_container_contents_with_limit(self):
        # get container contents list using limit param
        container_name = self._create_container()
        object_name = self._create_object(container_name)

        params = {'limit': data_utils.rand_int_id(1, 10000)}
        resp, object_list = self.container_client.list_container_contents(
            container_name, params=params)
        self.assertIn(int(resp['status']), HTTP_SUCCESS)
        self.assertHeaders(resp, 'Container', 'GET')
        self.assertEqual(object_name, object_list.strip('\n'))
Beispiel #58
0
 def test_get_queue_stats(self):
     # Retrieve random queue
     queue_name = self.queues[data_utils.rand_int_id(0,
                                                     len(self.queues) - 1)]
     # Get Queue Stats for a newly created Queue
     _, body = self.get_queue_stats(queue_name)
     msgs = body['messages']
     for element in ('free', 'claimed', 'total'):
         self.assertEqual(0, msgs[element])
     for element in ('oldest', 'newest'):
         self.assertNotIn(element, msgs)
 def test_create_security_group_rule_with_non_existent_id(self):
     # Negative test: Creation of Security Group rule should FAIL
     # with non existent Parent group id
     # Adding rules to the non existent Security Group id
     parent_group_id = data_utils.rand_int_id(start=999)
     ip_protocol = 'tcp'
     from_port = 22
     to_port = 22
     self.assertRaises(exceptions.NotFound,
                       self.client.create_security_group_rule,
                       parent_group_id, ip_protocol, from_port, to_port)
Beispiel #60
0
    def generate_message_body(cls, repeat=1):
        '''Wrapper utility that sets the metadata of a queue.'''
        message_ttl = data_utils.rand_int_id(start=60,
                                             end=CONF.queuing.max_message_ttl)

        key = data_utils.arbitrary_string(size=20, base_text='QueuingKey')
        value = data_utils.arbitrary_string(size=20, base_text='QueuingValue')
        message_body = {key: value}

        rbody = ([{'body': message_body, 'ttl': message_ttl}] * repeat)
        return rbody