def test_rand_uuid(self):
     actual = data_utils.rand_uuid()
     self.assertIsInstance(actual, str)
     self.assertRegexpMatches(actual, "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]"
                                      "{4}-[0-9a-f]{4}-[0-9a-f]{12}$")
     actual2 = data_utils.rand_uuid()
     self.assertNotEqual(actual, actual2)
Exemple #2
0
 def test_rand_uuid(self):
     actual = data_utils.rand_uuid()
     self.assertIsInstance(actual, str)
     self.assertRegexpMatches(
         actual, "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]"
         "{4}-[0-9a-f]{4}-[0-9a-f]{12}$")
     actual2 = data_utils.rand_uuid()
     self.assertNotEqual(actual, actual2)
Exemple #3
0
    def test_compare_console_output(self):
        key_name = data_utils.rand_name('testkey')
        pkey = self.create_key_pair(key_name)
        sec_group_name = self.create_standard_security_group()
        instance_id = self.run_instance(KeyName=key_name,
                                        SecurityGroups=[sec_group_name])

        data_to_check = data_utils.rand_uuid()
        ip_address = self.get_instance_ip(instance_id)
        ssh_client = ssh.Client(ip_address, CONF.aws.image_user, pkey=pkey)
        cmd = 'sudo sh -c "echo \\"%s\\" >/dev/console"' % data_to_check
        ssh_client.exec_command(cmd)

        waiter = base.EC2Waiter(self.client.get_console_output)
        waiter.wait_no_exception(InstanceId=instance_id)

        def _compare_console_output():
            data = self.client.get_console_output(InstanceId=instance_id)
            self.assertEqual(instance_id, data['InstanceId'])
            self.assertIsNotNone(data['Timestamp'])
            self.assertIn('Output', data)
            self.assertIn(data_to_check, data['Output'])

        waiter = base.EC2Waiter(_compare_console_output)
        waiter.wait_no_exception()
Exemple #4
0
def baymodel_data(**kwargs):
    """Generates random baymodel data

    Keypair and image id cannot be random for the baymodel to be valid due to
    validations for the presence of keypair and image id prior to baymodel
    creation.

    :param keypair_id: keypair name
    :param image_id: image id or name
    :returns: BayModelEntity with generated data
    """

    data = {
        "name": data_utils.rand_name('bay'),
        "coe": "swarm",
        "tls_disabled": False,
        "network_driver": None,
        "docker_volume_size": 3,
        "labels": {},
        "fixed_network": "192.168.0.0/24",
        "dns_nameserver": "8.8.8.8",
        "flavor_id": data_utils.rand_name('bay'),
        "external_network_id": str(data_utils.rand_uuid()),
        "keypair_id": data_utils.rand_name('bay'),
        "image_id": data_utils.rand_name('bay')
    }

    data.update(kwargs)
    model = baymodel_model.BayModelEntity.from_dict(data)

    return model
 def test_server_metadata_non_existent_server(self):
     # GET on a non-existent server should not succeed
     non_existent_server_id = data_utils.rand_uuid()
     self.assertRaises(lib_exc.NotFound,
                       self.client.get_server_metadata_item,
                       non_existent_server_id,
                       'test2')
Exemple #6
0
    def test_update_baymodel_404(self):
        patch_model = datagen.baymodel_name_patch_data()

        self.assertRaises(
            exceptions.NotFound,
            self.baymodel_client.patch_baymodel,
            data_utils.rand_uuid(), patch_model)
 def test_delete_metadata_non_existent_server(self):
     # Should not be able to delete metadata item from a non-existent server
     non_existent_server_id = data_utils.rand_uuid()
     self.assertRaises(lib_exc.NotFound,
                       self.client.delete_server_metadata_item,
                       non_existent_server_id,
                       'd')
Exemple #8
0
def bay_data(name=data_utils.rand_name('bay'),
             baymodel_id=data_utils.rand_uuid(),
             node_count=random_int(1, 5), discovery_url=gen_random_ip(),
             bay_create_timeout=random_int(1, 30),
             master_count=random_int(1, 5)):
    """Generates random bay data

    BayModel_id cannot be random for the bay to be valid due to
    validations for the presence of baymodel prior to baymodel
    creation.

    :param name: bay name (must be unique)
    :param baymodel_id: baymodel unique id (must already exist)
    :param node_count: number of agents for bay
    :param discovery_url: url provided for node discovery
    :param bay_create_timeout: timeout in minutes for bay create
    :param master_count: number of master nodes for the bay
    :returns: BayEntity with generated data
    """

    data = {
        "name": name,
        "baymodel_id": baymodel_id,
        "node_count": node_count,
        "discovery_url": None,
        "bay_create_timeout": bay_create_timeout,
        "master_count": master_count
    }
    model = bay_model.BayEntity.from_dict(data)

    return model
 def test_set_nonexistent_image_metadata_item(self):
     # Negative test: Metadata item should not be set to a
     # nonexistent image
     meta = {'os_distro': 'alt'}
     self.assertRaises(lib_exc.NotFound,
                       self.client.set_image_metadata_item,
                       data_utils.rand_uuid(), 'os_distro', meta)
 def test_resize_server_with_non_existent_flavor(self):
     # Resize a server with non-existent flavor
     nonexistent_flavor = data_utils.rand_uuid()
     self.assertRaises(lib_exc.BadRequest,
                       self.client.resize,
                       self.server_id,
                       flavor_ref=nonexistent_flavor)
Exemple #11
0
    def test_metadata(self):
        key_name = data_utils.rand_name('testkey')
        self.client.import_key_pair(KeyName=key_name,
                                    PublicKeyMaterial=PUBLIC_KEY_MATERIAL)
        self.addResourceCleanUp(self.client.delete_key_pair, KeyName=key_name)

        sec_group_name = self.create_standard_security_group()
        user_data = six.text_type(data_utils.rand_uuid()) + six.unichr(1071)
        instance_id = self.run_instance(KeyName=key_name, UserData=user_data,
                                        SecurityGroups=[sec_group_name])

        data = self.client.describe_instance_attribute(
            InstanceId=instance_id, Attribute='userData')
        self.assertEqual(
            data['UserData']['Value'],
            base64.b64encode(user_data.encode("utf-8")).decode("utf-8"))

        ip_address = self.get_instance_ip(instance_id)

        ssh_client = ssh.Client(ip_address, CONF.aws.image_user,
                                pkey=PRIVATE_KEY_MATERIAL)

        url = 'http://169.254.169.254'
        data = ssh_client.exec_command('curl %s/latest/user-data' % url)
        if isinstance(data, six.binary_type):
            data = data.decode("utf-8")
        self.assertEqual(user_data, data)

        data = ssh_client.exec_command('curl %s/latest/meta-data/ami-id' % url)
        self.assertEqual(CONF.aws.image_id, data)

        data = ssh_client.exec_command(
            'curl %s/latest/meta-data/public-keys/0/openssh-key' % url)
        # compare only keys. without 'sha-rsa' and owner
        self.assertEqual(PUBLIC_KEY_MATERIAL.split()[1], data.split()[1])
Exemple #12
0
def bay_data(name=data_utils.rand_name('bay'),
             baymodel_id=data_utils.rand_uuid(),
             node_count=random_int(1, 5),
             discovery_url=gen_random_ip(),
             bay_create_timeout=random_int(1, 30),
             master_count=random_int(1, 5)):
    """Generates random bay data

    BayModel_id cannot be random for the bay to be valid due to
    validations for the presence of baymodel prior to baymodel
    creation.

    :param name: bay name (must be unique)
    :param baymodel_id: baymodel unique id (must already exist)
    :param node_count: number of agents for bay
    :param discovery_url: url provided for node discovery
    :param bay_create_timeout: timeout in minutes for bay create
    :param master_count: number of master nodes for the bay
    :returns: BayEntity with generated data
    """

    data = {
        "name": name,
        "baymodel_id": baymodel_id,
        "node_count": node_count,
        "discovery_url": None,
        "bay_create_timeout": bay_create_timeout,
        "master_count": master_count
    }
    model = bay_model.BayEntity.from_dict(data)

    return model
Exemple #13
0
def baymodel_data(**kwargs):
    """Generates random baymodel data

    Keypair and image id cannot be random for the baymodel to be valid due to
    validations for the presence of keypair and image id prior to baymodel
    creation.

    :param keypair_id: keypair name
    :param image_id: image id or name
    :returns: BayModelEntity with generated data
    """

    data = {
        "name": data_utils.rand_name('bay'),
        "coe": "swarm",
        "tls_disabled": False,
        "network_driver": None,
        "volume_driver": None,
        "docker_volume_size": 3,
        "labels": {},
        "fixed_network": "192.168.0.0/24",
        "dns_nameserver": "8.8.8.8",
        "flavor_id": data_utils.rand_name('bay'),
        "master_flavor_id": data_utils.rand_name('bay'),
        "external_network_id": str(data_utils.rand_uuid()),
        "keypair_id": data_utils.rand_name('bay'),
        "image_id": data_utils.rand_name('bay')
    }

    data.update(kwargs)
    model = baymodel_model.BayModelEntity.from_dict(data)

    return model
    def test_userdata(self):
        key_name = data_utils.rand_name('testkey')
        pkey = self.create_key_pair(key_name)
        sec_group_name = self.create_standard_security_group()
        user_data = data_utils.rand_uuid()
        instance_id = self.run_instance(KeyName=key_name,
                                        UserData=user_data,
                                        SecurityGroups=[sec_group_name])

        resp, data = self.client.DescribeInstanceAttribute(
            InstanceId=instance_id, Attribute='userData')
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.assertEqual(data['UserData']['Value'],
                         base64.b64encode(user_data))

        ip_address = self.get_instance_ip(instance_id)

        ssh_client = ssh.Client(ip_address, CONF.aws.image_user, pkey=pkey)

        url = 'http://169.254.169.254'
        data = ssh_client.exec_command('curl %s/latest/user-data' % url)
        self.assertEqual(user_data, data)

        data = ssh_client.exec_command('curl %s/latest/meta-data/ami-id' % url)
        self.assertEqual(CONF.aws.image_id, data)
Exemple #15
0
 def test_create_port_nonexsistent_node_id(self):
     node_id = str(data_utils.rand_uuid())
     address = data_utils.rand_mac_address()
     self.assertRaises(lib_exc.BadRequest,
                       self.create_port,
                       node_id=node_id,
                       address=address)
 def test_rebuild_non_existent_server(self):
     # Rebuild a non existent server
     nonexistent_server = data_utils.rand_uuid()
     self.assertRaises(lib_exc.NotFound,
                       self.client.rebuild,
                       nonexistent_server,
                       self.image_ref_alt)
 def test_set_nonexistent_image_metadata_item(self):
     # Negative test: Metadata item should not be set to a
     # nonexistent image
     meta = {'os_distro': 'alt'}
     self.assertRaises(lib_exc.NotFound,
                       self.client.set_image_metadata_item,
                       data_utils.rand_uuid(), 'os_distro',
                       meta)
 def test_set_metadata_non_existent_server(self):
     # Set metadata on a non-existent server should not succeed
     non_existent_server_id = data_utils.rand_uuid()
     meta = {'meta1': 'data1'}
     self.assertRaises(lib_exc.NotFound,
                       self.client.set_server_metadata,
                       non_existent_server_id,
                       meta)
    def test_create_port_duplicated_port_uuid(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        uuid = data_utils.rand_uuid()

        self.create_port(node_id=node_id, address=address, uuid=uuid)
        self.assertRaises(lib_exc.Conflict, self.create_port, node_id=node_id,
                          address=address, uuid=uuid)
 def test_update_metadata_non_existent_server(self):
     # An update should not happen for a non-existent server
     non_existent_server_id = data_utils.rand_uuid()
     meta = {'key1': 'value1', 'key2': 'value2'}
     self.assertRaises(lib_exc.NotFound,
                       self.client.update_server_metadata,
                       non_existent_server_id,
                       meta)
Exemple #21
0
    def test_update_baymodel_invalid_patch(self):
        # get json object
        gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
        resp, old_model = self._create_baymodel(gen_model)

        self.assertRaises(
            exceptions.BadRequest,
            self.baymodel_client.patch_baymodel, data_utils.rand_uuid(),
            gen_model)
Exemple #22
0
    def test_create_port_specifying_uuid(self):
        node_id = self.node["uuid"]
        address = data_utils.rand_mac_address()
        uuid = data_utils.rand_uuid()

        _, port = self.create_port(node_id=node_id, address=address, uuid=uuid)

        _, body = self.client.show_port(uuid)
        self._assertExpected(port, body)
Exemple #23
0
    def test_create_port_specifying_uuid(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        uuid = data_utils.rand_uuid()

        _, port = self.create_port(node_id=node_id, address=address, uuid=uuid)

        _, body = self.client.show_port(uuid)
        self._assertExpected(port, body)
Exemple #24
0
 def _associate_node_with_instance(self):
     self.client.set_node_power_state(self.node['uuid'], 'power off')
     waiters.wait_for_bm_node_status(self.client, self.node['uuid'],
                                     'power_state', 'power off')
     instance_uuid = data_utils.rand_uuid()
     self.client.update_node(self.node['uuid'], instance_uuid=instance_uuid)
     self.addCleanup(self.client.update_node,
                     uuid=self.node['uuid'],
                     instance_uuid=None)
     return instance_uuid
Exemple #25
0
 def test_create_region_with_specific_id(self):
     # Create a region with a specific id
     r_region_id = data_utils.rand_uuid()
     r_description = data_utils.rand_name('description')
     region = self.client.create_region(r_description,
                                        unique_region_id=r_region_id)
     self.addCleanup(self._delete_region, region['id'])
     # Asserting Create Region with specific id response body
     self.assertEqual(r_region_id, region['id'])
     self.assertEqual(r_description, region['description'])
Exemple #26
0
 def test_create_region_with_specific_id(self):
     # Create a region with a specific id
     r_region_id = data_utils.rand_uuid()
     r_description = data_utils.rand_name('description')
     region = self.client.create_region(
         r_description, unique_region_id=r_region_id)
     self.addCleanup(self._delete_region, region['id'])
     # Asserting Create Region with specific id response body
     self.assertEqual(r_region_id, region['id'])
     self.assertEqual(r_description, region['description'])
Exemple #27
0
 def _associate_node_with_instance(self):
     self.client.set_node_power_state(self.node['uuid'], 'power off')
     waiters.wait_for_bm_node_status(self.client, self.node['uuid'],
                                     'power_state', 'power off')
     instance_uuid = data_utils.rand_uuid()
     self.client.update_node(self.node['uuid'],
                             instance_uuid=instance_uuid)
     self.addCleanup(self.client.update_node,
                     uuid=self.node['uuid'], instance_uuid=None)
     return instance_uuid
Exemple #28
0
    def test_create_port_duplicated_port_uuid(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        uuid = data_utils.rand_uuid()

        self.create_port(node_id=node_id, address=address, uuid=uuid)
        self.assertRaises(lib_exc.Conflict,
                          self.create_port,
                          node_id=node_id,
                          address=address,
                          uuid=uuid)
    def test_update_port_replace_node_id_with_nonexistent(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()

        _, port = self.create_port(node_id=node_id, address=address)
        port_id = port['uuid']

        patch = [{'path': '/node_uuid',
                  'op': 'replace',
                  'value': data_utils.rand_uuid()}]
        self.assertRaises(lib_exc.BadRequest,
                          self.client.update_port, port_id, patch)
 def _generate_a_non_existent_security_group_id(self):
     security_group_id = []
     body = self.client.list_security_groups()
     for i in range(len(body)):
         security_group_id.append(body[i]['id'])
     # Generate a non-existent security group id
     while True:
         non_exist_id = data_utils.rand_int_id(start=999)
         if self.neutron_available:
             non_exist_id = data_utils.rand_uuid()
         if non_exist_id not in security_group_id:
             break
     return non_exist_id
 def _generate_a_non_existent_security_group_id(self):
     security_group_id = []
     body = self.client.list_security_groups()
     for i in range(len(body)):
         security_group_id.append(body[i]['id'])
     # Generate a non-existent security group id
     while True:
         non_exist_id = data_utils.rand_int_id(start=999)
         if self.neutron_available:
             non_exist_id = data_utils.rand_uuid()
         if non_exist_id not in security_group_id:
             break
     return non_exist_id
Exemple #32
0
    def test_update_port_replace_node_id_with_nonexistent(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()

        _, port = self.create_port(node_id=node_id, address=address)
        port_id = port['uuid']

        patch = [{
            'path': '/node_uuid',
            'op': 'replace',
            'value': data_utils.rand_uuid()
        }]
        self.assertRaises(lib_exc.BadRequest, self.client.update_port, port_id,
                          patch)
Exemple #33
0
    def populate_smoke_table(self, table_name, keycount, count_per_key):
        """
        Put [keycont*count_per_key] autogenerated items to the table.

        In result, [keycount] unique hash key values
        and [count_per_key] items for each has key value are generated.

        For example, to generate some number of items for the only hash key,
        set keycount=1 and count_per_key=needed_number_of_items.
        """
        new_items = []
        for _ in range(keycount):
            forum = 'forum%s' % data_utils.rand_int_id()
            for i in range(count_per_key):
                item = self.put_smoke_item(
                    table_name, forum=forum, subject='subject%s' % i,
                    message=data_utils.rand_name(self.table_prefix),
                    last_posted_by=data_utils.rand_uuid(),
                    replies=str(data_utils.rand_int_id())
                )
                new_items.append(item)
        return new_items
Exemple #34
0
    def test_userdata(self):
        key_name = data_utils.rand_name('testkey')
        pkey = self.create_key_pair(key_name)
        sec_group_name = self.create_standard_security_group()
        user_data = data_utils.rand_uuid()
        instance_id = self.run_instance(KeyName=key_name, UserData=user_data,
                                        SecurityGroups=[sec_group_name])

        data = self.client.describe_instance_attribute(
            InstanceId=instance_id, Attribute='userData')
        self.assertEqual(data['UserData']['Value'],
                         base64.b64encode(user_data))

        ip_address = self.get_instance_ip(instance_id)

        ssh_client = ssh.Client(ip_address, CONF.aws.image_user, pkey=pkey)

        url = 'http://169.254.169.254'
        data = ssh_client.exec_command('curl %s/latest/user-data' % url)
        self.assertEqual(user_data, data)

        data = ssh_client.exec_command('curl %s/latest/meta-data/ami-id' % url)
        self.assertEqual(CONF.aws.image_id, data)
 def test_get_nonexistent_image(self):
     # Check raises a NotFound
     nonexistent_image = data_utils.rand_uuid()
     self.assertRaises(lib_exc.NotFound, self.client.get_image,
                       nonexistent_image)
 def test_create_port_nonexsistent_node_id(self):
     node_id = str(data_utils.rand_uuid())
     address = data_utils.rand_mac_address()
     self.assertRaises(lib_exc.BadRequest, self.create_port,
                       node_id=node_id, address=address)
 def test_get_nonexistent_image_metadata_item(self):
     # Negative test: Get on non-existent image should not happen
     self.assertRaises(lib_exc.NotFound,
                       self.client.show_image_metadata_item,
                       data_utils.rand_uuid(), 'os_version')
 def test_update_nonexistent_image_metadata(self):
     # Negative test:An update should not happen for a non-existent image
     meta = {'os_distro': 'alt1', 'os_version': 'alt2'}
     self.assertRaises(lib_exc.NotFound,
                       self.client.update_image_metadata,
                       data_utils.rand_uuid(), meta)
 def test_restore_nonexistent_server_id(self):
     # restore-delete a non existent server
     nonexistent_server = data_utils.rand_uuid()
     self.assertRaises(lib_exc.NotFound,
                       self.client.restore_soft_deleted_server,
                       nonexistent_server)
 def test_get_nonexistent_image_metadata_item(self):
     # Negative test: Get on non-existent image should not happen
     self.assertRaises(lib_exc.NotFound,
                       self.client.get_image_metadata_item,
                       data_utils.rand_uuid(), 'os_version')
 def test_set_nonexistent_image_metadata(self):
     # Negative test: Metadata should not be set to a non-existent image
     meta = {'os_distro': 'alt1', 'os_version': 'alt2'}
     self.assertRaises(lib_exc.NotFound, self.client.set_image_metadata,
                       data_utils.rand_uuid(), meta)
 def test_list_nonexistent_image_metadata(self):
     # Negative test: List on nonexistent image
     # metadata should not happen
     self.assertRaises(lib_exc.NotFound, self.client.list_image_metadata,
                       data_utils.rand_uuid())
 def test_force_delete_nonexistent_server_id(self):
     # force-delete a non existent server
     nonexistent_server = data_utils.rand_uuid()
     self.assertRaises(lib_exc.NotFound,
                       self.client.force_delete_server,
                       nonexistent_server)
Exemple #44
0
 def test_delete_bay_for_nonexisting_bay(self):
     self.assertRaises(exceptions.NotFound, self.bay_client.delete_bay,
                       data_utils.rand_uuid())
 def test_delete_nonexistent_image_metadata_item(self):
     # Negative test: Shouldn't be able to delete metadata
     # item from non-existent image
     self.assertRaises(lib_exc.NotFound,
                       self.client.delete_image_metadata_item,
                       data_utils.rand_uuid(), 'os_distro')
 def test_list_nonexistent_image_metadata(self):
     # Negative test: List on nonexistent image
     # metadata should not happen
     self.assertRaises(lib_exc.NotFound, self.client.list_image_metadata,
                       data_utils.rand_uuid())
 def test_set_nonexistent_image_metadata(self):
     # Negative test: Metadata should not be set to a non-existent image
     meta = {'os_distro': 'alt1', 'os_version': 'alt2'}
     self.assertRaises(lib_exc.NotFound, self.client.set_image_metadata,
                       data_utils.rand_uuid(), meta)
Exemple #48
0
 def test_show_port_nonexistent_uuid(self):
     self.assertRaises(lib_exc.NotFound, self.client.show_port,
                       data_utils.rand_uuid())
 def test_get_console_output_of_non_existent_server(self):
     # get the console output for a non existent server
     nonexistent_server = data_utils.rand_uuid()
     self.assertRaises(lib_exc.NotFound,
                       self.client.get_console_output,
                       nonexistent_server, 10)
 def test_delete_nonexistent_image_metadata_item(self):
     # Negative test: Shouldn't be able to delete metadata
     # item from non-existent image
     self.assertRaises(lib_exc.NotFound,
                       self.client.delete_image_metadata_item,
                       data_utils.rand_uuid(), 'os_distro')
 def test_update_nonexistent_image_metadata(self):
     # Negative test:An update should not happen for a non-existent image
     meta = {'os_distro': 'alt1', 'os_version': 'alt2'}
     self.assertRaises(lib_exc.NotFound, self.client.update_image_metadata,
                       data_utils.rand_uuid(), meta)
 def test_show_port_nonexistent_uuid(self):
     self.assertRaises(lib_exc.NotFound, self.client.show_port,
                       data_utils.rand_uuid())
 def test_unshelve_non_existent_server(self):
     # unshelve a non existent server
     nonexistent_server = data_utils.rand_uuid()
     self.assertRaises(lib_exc.NotFound, self.client.unshelve_server,
                       nonexistent_server)
 def test_list_server_metadata_non_existent_server(self):
     # List metadata on a non-existent server should not succeed
     non_existent_server_id = data_utils.rand_uuid()
     self.assertRaises(lib_exc.NotFound,
                       self.client.list_server_metadata,
                       non_existent_server_id)
Exemple #55
0
 def test_delete_baymodel_404(self):
     self.assertRaises(
         exceptions.NotFound,
         self.baymodel_client.delete_baymodel, data_utils.rand_uuid())