Beispiel #1
0
 def get_boot_image_name(self, name="cirros-0.3.4-x86_64-disk.img"):
     raw_output = self.cliclient.openstack(action='image list')
     all_images = output_parser.listing(raw_output)
     boot_img = list(
         filter(lambda x: str(x['Name']).lower() == name, all_images))
     self.assertNotEmpty(boot_img)
     return boot_img[0]['Name']
Beispiel #2
0
 def get_network_id(self, name="public"):
     raw_output = self.cliclient.openstack(action='network list')
     all_networks = output_parser.listing(raw_output)
     public_net = list(
         filter(lambda x: str(x['Name']).lower() == name, all_networks))
     self.assertNotEmpty(public_net)
     return public_net[0]['ID']
Beispiel #3
0
    def test_shutdown_active_controller_during_upload(self,
                                                      glance,
                                                      image_file,
                                                      suffix,
                                                      timeout=60):
        """Check that image is created successfully if during creating image
        to perform shutdown of active controller

        Steps:
            1. Create image using URL Link
            2. Shutdown active controller during creation of image
            3. Check that image is present in list and image status is `active`
            4. Delete created image
            5. Check that image deleted
        """

        # Find a primary controller
        primary_controller = self.env.primary_controller
        mac = primary_controller.data['mac']
        self.primary_node = DevopsClient.get_node_by_mac(
            env_name=self.env_name, mac=mac)

        name = 'Test_{}'.format(suffix[:6])
        image_url = settings.GLANCE_IMAGE_URL
        cmd = ('image-create --name {name} --container-format bare '
               '--disk-format qcow2 --location {image_url}'.format(
                   name=name, image_url=image_url))
        image = parser.details(glance(cmd))
        logger.info('Image starts to upload')

        # Shutdown primary controller
        self.env.warm_shutdown_nodes([self.primary_node])

        image_list = parser.listing(glance('image-list'))
        assert image['id'] in [x['ID'] for x in image_list]

        image_data = parser.details(glance('image-show {id}'.format(**image)))
        assert image_data['status'] == 'active'
        logger.info('Image is active')

        glance('image-delete {id}'.format(**image))

        images = parser.listing(glance('image-list'))
        assert image['id'] not in [x['ID'] for x in images]
def test_limits_feature(env):
    """Test case for Ceilometer mandatory limits feature.

    Actions:
        1. Generate data in MongoDB with a help of 'mongo-generator.py'
        2. Run 'ceilometer meter-list' and check that number of items == 100
        3. Run 'ceilometer sample-list' and check that number of items == 100
        4. Run 'ceilometer resource-list' and check that number of items == 100
        5. Run 'ceilometer event-list --no-traits' and check that number
            of items == 100
    """
    script_name = 'mongo-generator.py'
    script_path = scripts_dir_path() + script_name

    set_env = 'source /root/openrc && '
    ceil_meter_list = set_env + 'ceilometer meter-list'
    ceil_sample_list = set_env + 'ceilometer sample-list'
    ceil_res_list = set_env + 'ceilometer resource-list'
    ceil_event_list = set_env + 'ceilometer event-list --no-traits'

    with env.get_nodes_by_role('controller')[0].ssh() as remote:
        remote.upload(script_path, '/root/{0}'.format(script_name))
        cmd = ('python /root/{0} --users 1 --projects 1 '
               '--resources_per_user_project 200 '
               '--samples_per_user_project 1000').format(script_name)
        remote.check_call(cmd)
        ceil_meter_list_out = remote.check_call(ceil_meter_list)['stdout']
        ceil_sample_list_out = remote.check_call(ceil_sample_list)['stdout']
        ceil_res_list_out = remote.check_call(ceil_res_list)['stdout']
        ceil_event_list_out = remote.check_call(ceil_event_list)['stdout']

    ceil_meter_list_out = parser.listing(ceil_meter_list_out)
    ceil_sample_list_out = parser.listing(ceil_sample_list_out)
    ceil_res_list_out = parser.listing(ceil_res_list_out)
    ceil_event_list_out = parser.listing(ceil_event_list_out)

    assert all(i == 100
               for i in (
                   len(ceil_meter_list_out),
                   len(ceil_sample_list_out),
                   len(ceil_res_list_out),
                   len(ceil_event_list_out)))
Beispiel #5
0
 def create_host_aggregate(self, name="", availabilityzone=""):
     if not name:
         name = 'AggName' + str(self.getUniqueInteger())
     if not availabilityzone:
         availabilityzone = 'AvZ' + str(self.getUniqueInteger())
     raw_output = self.cliclient.nova(action='aggregate-create',
                                      params=name + ' ' + availabilityzone)
     LOG.info("create_host_aggregate() raw output %s", raw_output)
     new_zone = output_parser.listing(raw_output)
     self.assertNotEqual(len(new_zone), 0)
     return new_zone[0]
def test_download_zero_size_image(glance, message):
    image = parser.details(glance('image-create'))

    for command in ('image-download {id}', 'image-download {id} --progress'):
        out = glance(command.format(**image), fail_ok=True, merge_stderr=True)
        assert message.format(**image) in out

    glance('image-delete {id}'.format(**image))

    images = parser.listing(glance('image-list'))
    assert image['id'] not in [x['ID'] for x in images]
    def test_shutdown_active_controller_during_upload(
            self, glance, image_file, suffix, timeout=60):
        """Check that image is created successfully if during creating image
        to perform shutdown of active controller

        Steps:
            1. Create image using URL Link
            2. Shutdown active controller during creation of image
            3. Check that image is present in list and image status is `active`
            4. Delete created image
            5. Check that image deleted
        """

        # Find a primary controller
        primary_controller = self.env.primary_controller
        mac = primary_controller.data['mac']
        self.primary_node = DevopsClient.get_node_by_mac(
            env_name=self.env_name, mac=mac)

        name = 'Test_{}'.format(suffix[:6])
        image_url = settings.GLANCE_IMAGE_URL
        cmd = ('image-create --name {name} --container-format bare '
               '--disk-format qcow2 --location {image_url}'.format(
                    name=name, image_url=image_url))
        image = parser.details(glance(cmd))
        logger.info('Image starts to upload')

        # Shutdown primary controller
        self.env.warm_shutdown_nodes([self.primary_node])

        image_list = parser.listing(glance('image-list'))
        assert image['id'] in [x['ID'] for x in image_list]

        image_data = parser.details(glance('image-show {id}'.format(**image)))
        assert image_data['status'] == 'active'
        logger.info('Image is active')

        glance('image-delete {id}'.format(**image))

        images = parser.listing(glance('image-list'))
        assert image['id'] not in [x['ID'] for x in images]
Beispiel #8
0
    def test_shutdown_primary_controller(self,
                                         glance,
                                         image_file,
                                         suffix,
                                         timeout=60):
        """Check creating image after shutdown primary controller

        Steps:
            1. Shutdown primary controller
            2. Create image from `image_file`
            3. Check that image is present in list and image status is `active`
            4. Delete created image
            5. Check that image deleted
        """
        # Find a primary controller
        primary_controller = self.env.primary_controller
        mac = primary_controller.data['mac']
        primary_node = DevopsClient.get_node_by_mac(env_name=self.env_name,
                                                    mac=mac)

        # Shutdown primary controller
        self.env.warm_shutdown_nodes([primary_node])

        name = 'Test_{}'.format(suffix[:6])
        cmd = ('image-create --name {name} --container-format bare '
               '--disk-format qcow2 --file {file}'.format(name=name,
                                                          file=image_file))
        image = parser.details(glance(cmd))
        logger.info('Image starts to upload')

        image_list = parser.listing(glance('image-list'))
        assert image['id'] in [x['ID'] for x in image_list]

        image_data = parser.details(glance('image-show {id}'.format(**image)))
        assert image_data['status'] == 'active'
        logger.info('Image is active')

        glance('image-delete {id}'.format(**image))

        images = parser.listing(glance('image-list'))
        assert image['id'] not in [x['ID'] for x in images]
Beispiel #9
0
def test_upload_image_wo_disk_format_and_container_format(image_file, glance):
    """Checks that disk-format and container-format are required"""
    name = 'Test_{0}'.format(str(uuid.uuid4())[:6])
    cmd = 'image-create --name {name} --file {path} --progress'.format(
        name=name, path=image_file)
    out = glance(cmd, fail_ok=True, merge_stderr=True)
    assert 'error: Must provide' in out
    assert '--container-format' in out
    assert '--disk-format' in out
    assert 'when using --file' in out
    images = parser.listing(glance('image-list'))
    assert name not in [x['Name'] for x in images]
def test_upload_image_wo_disk_format_and_container_format(image_file, glance):
    """Checks that disk-format and container-format are required"""
    name = 'Test_{0}'.format(str(uuid.uuid4())[:6])
    cmd = 'image-create --name {name} --file {path} --progress'.format(
        name=name, path=image_file)
    out = glance(cmd, fail_ok=True, merge_stderr=True)
    assert 'error: Must provide' in out
    assert '--container-format' in out
    assert '--disk-format' in out
    assert 'when using --file' in out
    images = parser.listing(glance('image-list'))
    assert name not in [x['Name'] for x in images]
Beispiel #11
0
def test_share_glance_image(glance, user, project, image_file, suffix):
    """Check sharing glance image to another project

    Scenario:
        1. Create image from `image_file`
        2. Check that image is present in list and image status is `active`
        3. Bind another project to image
        4. Check that binded project id is present in image member list
        5. Unbind project from image
        6. Check that project id is not present in image member list
        7. Delete image
        8. Check that image deleted
    """
    name = "Test_{0}".format(suffix[:6])
    cmd = ("image-create --name {name} --container-format bare --disk-format "
           "qcow2 --file {file} --progress".format(name=name,
                                                   file=image_file))
    image = parser.details(glance(cmd))

    check_image_active(glance, image)

    check_image_in_list(glance, image)

    glance('member-create {id} {project_id}'.format(project_id=project['id'],
                                                    **image))

    member_list = parser.listing(glance('member-list --image-id {id}'.format(
        **image)))
    assert project['id'] in [x['Member ID'] for x in member_list]

    glance('member-delete {id} {project_id}'.format(project_id=project['id'],
                                                    **image))

    member_list = parser.listing(glance('member-list --image-id {id}'.format(
        **image)))
    assert project['id'] not in [x['Member ID'] for x in member_list]

    glance('image-delete {id}'.format(**image))

    check_image_not_in_list(glance, image)
Beispiel #12
0
def test_limits_feature(env):
    """Test case for Ceilometer mandatory limits feature.

    Actions:
        1. Generate data in MongoDB with a help of 'mongo-generator.py'
        2. Run 'ceilometer meter-list' and check that number of items == 100
        3. Run 'ceilometer sample-list' and check that number of items == 100
        4. Run 'ceilometer resource-list' and check that number of items == 100
        5. Run 'ceilometer event-list --no-traits' and check that number
            of items == 100
    """
    script_name = 'mongo-generator.py'
    script_path = scripts_dir_path() + script_name

    set_env = 'source /root/openrc && '
    ceil_meter_list = set_env + 'ceilometer meter-list'
    ceil_sample_list = set_env + 'ceilometer sample-list'
    ceil_res_list = set_env + 'ceilometer resource-list'
    ceil_event_list = set_env + 'ceilometer event-list --no-traits'

    with env.get_nodes_by_role('controller')[0].ssh() as remote:
        remote.upload(script_path, '/root/{0}'.format(script_name))
        cmd = ('python /root/{0} --users 1 --projects 1 '
               '--resources_per_user_project 200 '
               '--samples_per_user_project 1000').format(script_name)
        remote.check_call(cmd)
        ceil_meter_list_out = remote.check_call(ceil_meter_list)['stdout']
        ceil_sample_list_out = remote.check_call(ceil_sample_list)['stdout']
        ceil_res_list_out = remote.check_call(ceil_res_list)['stdout']
        ceil_event_list_out = remote.check_call(ceil_event_list)['stdout']

    ceil_meter_list_out = parser.listing(ceil_meter_list_out)
    ceil_sample_list_out = parser.listing(ceil_sample_list_out)
    ceil_res_list_out = parser.listing(ceil_res_list_out)
    ceil_event_list_out = parser.listing(ceil_event_list_out)

    assert all(i == 100
               for i in (len(ceil_meter_list_out), len(ceil_sample_list_out),
                         len(ceil_res_list_out), len(ceil_event_list_out)))
Beispiel #13
0
def test_download_zero_size_image(glance_remote, message):
    image = parser.details(glance_remote('image-create'))

    for command in ('image-download {id}', 'image-download {id} --progress'):
        out = glance_remote(command.format(**image),
                            fail_ok=True,
                            merge_stderr=True)
        assert message.format(**image) in out

    glance_remote('image-delete {id}'.format(**image))

    images = parser.listing(glance_remote('image-list'))
    assert image['id'] not in [x['ID'] for x in images]
    def test_shutdown_primary_controller(
            self, glance, image_file, suffix, timeout=60):
        """Check creating image after shutdown primary controller

        Steps:
            1. Shutdown primary controller
            2. Create image from `image_file`
            3. Check that image is present in list and image status is `active`
            4. Delete created image
            5. Check that image deleted
        """
        # Find a primary controller
        primary_controller = self.env.primary_controller
        mac = primary_controller.data['mac']
        primary_node = DevopsClient.get_node_by_mac(
            env_name=self.env_name, mac=mac)

        # Shutdown primary controller
        self.env.warm_shutdown_nodes([primary_node])

        name = 'Test_{}'.format(suffix[:6])
        cmd = ('image-create --name {name} --container-format bare '
               '--disk-format qcow2 --file {file}'.format(
                    name=name, file=image_file))
        image = parser.details(glance(cmd))
        logger.info('Image starts to upload')

        image_list = parser.listing(glance('image-list'))
        assert image['id'] in [x['ID'] for x in image_list]

        image_data = parser.details(glance('image-show {id}'.format(**image)))
        assert image_data['status'] == 'active'
        logger.info('Image is active')

        glance('image-delete {id}'.format(**image))

        images = parser.listing(glance('image-list'))
        assert image['id'] not in [x['ID'] for x in images]
    def rabbitmqadmin_get_queue(self, user, passwd):
        """Get get queue=conductor from rabbitmqadmin.
        :param user: RabbitMQ username.
        :param passwd: RabbitMQ password.
        :return: Parsed output.
        """
        logger.debug("Get queue from rabbitmqadmin")

        controller = random.choice(self.env.get_nodes_by_role('controller'))
        with controller.ssh() as remote:
            out = remote.check_call(
                self.cmd.rabbitmqctl.get_queue.format(usr=user, pwd=passwd))
        out = out.stdout_string
        return output_parser.listing(out)
Beispiel #16
0
    def get_state_of_booted_instance(self, instance_id):
        time_interval = 10
        wait_until = datetime.now() + timedelta(seconds=time_interval)
        while datetime.now() < wait_until:
            ret_val = self.cliclient.nova(action='list')
            all_instances = output_parser.listing(ret_val)
            instance_state = list(
                filter(lambda x: x['ID'] == instance_id, all_instances))
            self.assertNotEmpty(instance_state)
            if instance_state[0]['Status'] == 'ACTIVE' and instance_state[0][
                    'Power State'] == 'Running':
                return True

        return False
Beispiel #17
0
    def get_compute_host_details(self):
        raw_output = self.cliclient.nova(action='host-list')
        all_hosts = output_parser.listing(raw_output)
        LOG.info("get_compute_host_details listing %s type %s", str(all_hosts),
                 str(type(all_hosts)))

        self.assertNotEmpty(all_hosts)
        # Filter the host list for compute nodes only
        compute_hosts = list(
            filter(lambda x: str(x['service']).lower() == 'compute',
                   all_hosts))
        LOG.info("compute_hosts %s", str(compute_hosts))
        self.assertNotEmpty(compute_hosts)
        return compute_hosts[0]
Beispiel #18
0
 def boot_image_on_aggregate_zone(self):
     raw_output = self.cliclient.nova(
         action='boot',
         params='--flavor 1' + ' --image=' + self.boot_image_name +
         ' --nic net-id=' + self.network_id + ' --availability-zone=' +
         self.ag_zone_name + ' ' + self.getUniqueString('TestInstance'))
     instance_info = output_parser.listing(raw_output)
     LOG.info("Output of boot image %s", instance_info)
     instance_id = None
     instance_id = list(
         filter(lambda x: str(x['Property']).lower() == 'id',
                instance_info))
     LOG.info("Instance information %s", instance_id)
     self.assertNotEmpty(instance_id)
     return instance_id[0]['Value']
    def test_numa_flavor_creation(self):
	LOG.info("BEGIN: test_numa_flavor_creation()")
	if not self.flavor_name:
	    self.flavor_name = 'NumaFlavor' + str(self.get_random_integer())
	raw_output = self.openstack.flavor_create(self.flavor_name)
	LOG.info("create_flavor() raw output \n%s", raw_output)
	new_flavor = output_parser.listing(raw_output)
        self.assertNotEmpty(new_flavor)
	
	#Add metadata to flavor
	self.add_metadata_to_flavor()
	
	# Delete the Flavor
        self.delete_flavor()
        LOG.info("END: test_numa_flavor_creation")
Beispiel #20
0
 def listing(self):
     return parser.listing(self)
Beispiel #21
0
    def get_hosts_in_aggregate(self, aggr_name):
	raw_output = self.openstack_api.aggregate_show(aggr_name)
        aggr_details = output_parser.listing(raw_output)
        raw_hosts_output = [x['Value'] for x in aggr_details if str(x['Field']).lower() == 'hosts'][0]
        hosts = raw_hosts_output.strip("[]").replace("u'", "").replace("'","")
   	return hosts
Beispiel #22
0
    def get_metadata_in_aggregate(self, aggr_name):
	raw_output = self.openstack_api.aggregate_show(aggr_name)
        aggr_details = output_parser.listing(raw_output)
        metadata = [x['Value'] for x in aggr_details if str(x['Field']).lower() == 'properties'][0]
	return metadata
Beispiel #23
0
 def parse_listing(self, raw_output):
     """Return list of dicts with basic item parsed from cli output."""
     return output_parser.listing(raw_output)
Beispiel #24
0
 def test_listing(self):
     expected = [{'ID': '11'}, {'ID': '21'}, {'ID': '31'}]
     actual = output_parser.listing(self.LISTING_OUTPUT)
     self.assertIsInstance(actual, list)
     self.assertEqual(expected, actual)
Beispiel #25
0
 def parse_listing(self, raw_output):
     """Return list of dicts with basic item parsed from cli output."""
     return output_parser.listing(raw_output)
Beispiel #26
0
 def test_listing(self):
     expected = [{"ID": "11"}, {"ID": "21"}, {"ID": "31"}]
     actual = output_parser.listing(self.LISTING_OUTPUT)
     self.assertIsInstance(actual, list)
     self.assertEqual(expected, actual)
Beispiel #27
0
def check_image_not_in_list(glance, image):
    __tracebackhide__ = True
    image_list = parser.listing(glance('image-list'))
    if image['id'] in [x['ID'] for x in image_list]:
        pytest.fail('There is image {id} in list'.format(**image))
 def listing(self):
     return parser.listing(self)
Beispiel #29
0
 def test_listing(self):
     expected = [{'ID': '11'}, {'ID': '21'}, {'ID': '31'}]
     actual = output_parser.listing(self.LISTING_OUTPUT)
     self.assertIsInstance(actual, list)
     self.assertEqual(expected, actual)