Beispiel #1
0
def configure_cinder_backup():
    """Configure cinder-backup-swift-proxy."""
    keystone_ip = zaza_model.get_app_ips(
        'swift-keystone')[0]
    swift_ip = zaza_model.get_app_ips(
        'swift-proxy')[0]
    auth_ver = (zaza_model.get_application_config('swift-keystone')
                .get('preferred-api-version').get('value'))
    if auth_ver == 2:
        auth_url = 'http://{}:5000/v2.0'.format(keystone_ip)
        endpoint_url = 'http://{}:8080/v1/AUTH_'.format(swift_ip)
    else:
        auth_url = 'http://{}:5000/v3'.format(keystone_ip)
        endpoint_url = 'http://{}:8080/v1/AUTH'.format(swift_ip)
    cinder_backup_swift_proxy_conf = {
        'endpoint-url': endpoint_url,
        'auth-url': auth_url
    }
    juju_service = 'cinder-backup-swift-proxy'
    zaza_model.set_application_config(juju_service,
                                      cinder_backup_swift_proxy_conf)
    zaza_model.wait_for_agent_status()
    zaza_model.wait_for_application_states()
    _singleton = zaza.openstack.charm_tests.test_utils.OpenStackBaseTest()
    _singleton.setUpClass()
    with _singleton.config_change(cinder_backup_swift_proxy_conf,
                                  cinder_backup_swift_proxy_conf):
        # wait for configuration to be applied then return
        pass
def nfs_setup():
    """Run setup for testing Trilio.

    Setup for testing Trilio is currently part of functional
    tests.
    """
    logging.info("Configuring NFS Server")
    nfs_server_ip = zaza_model.get_app_ips("nfs-server-test-fixture")[0]
    trilio_wlm_unit = zaza_model.get_first_unit_name("trilio-wlm")

    nfs_shares_conf = {"nfs-shares": "{}:/srv/testing".format(nfs_server_ip)}
    logging.info("NFS share config: {}".format(nfs_shares_conf))
    _trilio_services = ["trilio-wlm", "trilio-data-mover"]

    conf_changed = False
    for juju_service in _trilio_services:
        app_config = zaza_model.get_application_config(juju_service)
        if app_config["nfs-shares"] != nfs_shares_conf["nfs-shares"]:
            logging.info("Updating nfs-shares config option")
            zaza_model.set_application_config(juju_service, nfs_shares_conf)
            conf_changed = True

    if conf_changed:
        zaza_model.wait_for_agent_status()
        # NOTE(jamespage): wlm-api service must be running in order
        #                  to execute the setup actions
        zaza_model.block_until_service_status(
            unit_name=trilio_wlm_unit,
            services=["wlm-api"],
            target_status="active",
        )
def basic_setup():
    """Run setup for testing Trilio.

    Setup for testing Trilio is currently part of functional
    tests.
    """
    logging.info("Configuring NFS Server")
    nfs_server_ip = zaza_model.get_app_ips("nfs-server-test-fixture")[0]
    trilio_wlm_unit = zaza_model.get_first_unit_name("trilio-wlm")

    nfs_shares_conf = {"nfs-shares": "{}:/srv/testing".format(nfs_server_ip)}
    _trilio_services = ["trilio-wlm", "trilio-data-mover"]

    conf_changed = False
    for juju_service in _trilio_services:
        app_config = zaza_model.get_application_config(juju_service)
        if app_config["nfs-shares"] != nfs_shares_conf["nfs-shares"]:
            zaza_model.set_application_config(juju_service, nfs_shares_conf)
            conf_changed = True

    if conf_changed:
        zaza_model.wait_for_agent_status()
        # NOTE(jamespage): wlm-api service must be running in order
        #                  to execute the setup actions
        zaza_model.block_until_service_status(
            unit_name=trilio_wlm_unit,
            services=["wlm-api"],
            target_status="active",
        )

    logging.info("Executing create-cloud-admin-trust")
    password = juju_utils.leader_get("keystone", "admin_passwd")

    generic_utils.assertActionRanOK(
        zaza_model.run_action_on_leader(
            "trilio-wlm",
            "create-cloud-admin-trust",
            raise_on_failure=True,
            action_params={"password": password},
        )
    )

    logging.info("Executing create-license")
    test_license = os.environ.get("TEST_TRILIO_LICENSE")
    if test_license and os.path.exists(test_license):
        zaza_model.attach_resource("trilio-wlm",
                                   resource_name='license',
                                   resource_path=test_license)
        generic_utils.assertActionRanOK(
            zaza_model.run_action_on_leader(
                "trilio-wlm", "create-license",
                raise_on_failure=True
            )
        )

    else:
        logging.error("Unable to find Trilio License file")
Beispiel #4
0
 def test_wait_for_agent_status_timeout(self):
     async def _block_until(f, timeout=None):
         if not f():
             raise asyncio.futures.TimeoutError
     self.patch_object(model, 'get_juju_model', return_value='mname')
     self.patch_object(model, 'Model')
     self.Model.return_value = self.Model_mock
     self.Model_mock.block_until.side_effect = _block_until
     with self.assertRaises(asyncio.futures.TimeoutError):
         model.wait_for_agent_status(timeout=0.1)
Beispiel #5
0
 def test_wait_for_agent_status(self):
     async def _block_until(f, timeout=None):
         if not f():
             raise asyncio.futures.TimeoutError
     self.patch_object(model, 'get_juju_model', return_value='mname')
     self.patch_object(model, 'Model')
     self.unit1.data = {'agent-status': {'current': 'idle'}}
     self.unit2.data = {'agent-status': {'current': 'executing'}}
     self.Model.return_value = self.Model_mock
     self.Model_mock.block_until.side_effect = _block_until
     model.wait_for_agent_status(timeout=0.1)
Beispiel #6
0
def configure_external_s3_backend():
    """Set up Ceph-radosgw as an external S3 backend for Glance."""
    logging.info("Creating a test S3 user and credentials for Glance")
    username, displayname = "zaza-glance-test", "Zaza Glance Test User"
    cmd = "radosgw-admin user create --uid='{}' --display-name='{}'".format(
        username, displayname)
    results = model.run_on_leader("ceph-mon", cmd)
    stdout = json.loads(results["stdout"])
    keys = stdout["keys"][0]
    access_key, secret_key = keys["access_key"], keys["secret_key"]

    logging.info("Getting S3 endpoint URL of Radosgw from Keystone")
    keystone_auth = openstack_utils.get_overcloud_auth()
    keystone_client = openstack_utils.get_keystone_client(keystone_auth)
    endpoint_url = keystone_client.session.get_endpoint(
        service_type="s3",
        interface="public",
        region="RegionOne",
    )

    logging.info("Creating a test S3 bucket for Glance")
    bucket_name = "zaza-glance-s3-test"
    s3_client = boto3.client(
        "s3",
        endpoint_url=endpoint_url,
        aws_access_key_id=access_key,
        aws_secret_access_key=secret_key,
    )
    s3_client.create_bucket(Bucket=bucket_name)

    logging.info("Updating Glance configs with S3 endpoint information")
    model.set_application_config(
        "glance",
        {
            "s3-store-host": endpoint_url,
            "s3-store-access-key": access_key,
            "s3-store-secret-key": secret_key,
            "s3-store-bucket": bucket_name,
        },
    )
    model.wait_for_agent_status()

    logging.info("Waiting for units to reach target states")
    model.wait_for_application_states(
        states={
            "glance": {
                "workload-status": "active",
                "workload-status-message": "Unit is ready",
            }
        })
    model.block_until_all_units_idle()
Beispiel #7
0
def configure_s3_backend():
    """Inject S3 parameters from Swift for Gnocchi config."""
    session = openstack_utils.get_overcloud_keystone_session()
    ks_client = openstack_utils.get_keystone_session_client(session)

    logging.info('Retrieving S3 connection data from Swift')
    token_data = ks_client.tokens.get_token_data(session.get_token())
    project_id = token_data['token']['project']['id']
    user_id = token_data['token']['user']['id']

    # Store URL to service providing S3 compatible API
    for entry in token_data['token']['catalog']:
        if entry['type'] == 's3':
            for endpoint in entry['endpoints']:
                if endpoint['interface'] == 'public':
                    s3_region = endpoint['region']
                    s3_endpoint = endpoint['url']

    # Create AWS compatible application credentials in Keystone
    ec2_creds = ks_client.ec2.create(user_id, project_id)

    logging.info('Changing Gnocchi charm config to connect to S3')
    model.set_application_config(
        'gnocchi', {
            's3-endpoint-url': s3_endpoint,
            's3-region-name': s3_region,
            's3-access-key-id': ec2_creds.access,
            's3-secret-access-key': ec2_creds.secret
        })
    logging.info('Waiting for units to execute config-changed hook')
    model.wait_for_agent_status()
    logging.info('Waiting for units to reach target states')
    model.wait_for_application_states(
        states={
            'gnocchi': {
                'workload-status-': 'active',
                'workload-status-message': 'Unit is ready'
            },
            'ceilometer': {
                'workload-status':
                'blocked',
                'workload-status-message':
                'Run the ' + 'ceilometer-upgrade action on the leader ' +
                'to initialize ceilometer and gnocchi'
            }
        })
    model.block_until_all_units_idle()
def upgrade_non_base_services(juju_status=None, switch=None):
    if not juju_status:
        juju_status = get_juju_status()
    # Upgrade the rest
    for svc in juju_status['applications']:
        if svc not in BASE_CHARMS:
            charm_name = charm_to_charm_name(
                juju_status['applications'][svc]['charm'])
            upgrade_service(svc, charm_name=charm_name, switch=switch)
    model.wait_for_agent_status(status='executing')
    if not model.get_relation_id('rabbitmq-server',
                                 'ceilometer-agent',
                                 remote_interface_name='amqp'):
        logging.info("Adding rabbitmq-server ceilometer-agent relation")
        model.add_relation('ceilometer-agent', 'amqp', 'rabbitmq-server:amqp')
        model.wait_for_agent_status(status='executing')
    if not model.get_relation_id('memcached',
                                 'nova-cloud-controller',
                                 remote_interface_name='memcache'):
        logging.info("Adding nova-cloud-controller memcached relation")
        model.add_relation('memcached', 'nova-cloud-controller',
                           'nova-cloud-controller:memcache')
        model.wait_for_agent_status(status='executing')
    logging.info("Waiting for units to be idle")
    model.block_until_all_units_idle()
Beispiel #9
0
 def _set_config(self, state):
     s = "True" if state else "False"
     config = {"use-policyd-override": s}
     logging.info("Setting config to {}".format(config))
     zaza_model.set_application_config(self.application_name, config)
     zaza_model.wait_for_agent_status()
Beispiel #10
0
    def config_change(self,
                      default_config,
                      alternate_config,
                      application_name=None):
        """Run change config tests.

        Change config to `alternate_config`, wait for idle workload status,
        yield, return config to `default_config` and wait for idle workload
        status before return from function.

        Example usage:
            with self.config_change({'preferred-api-version': '2'},
                                    {'preferred-api-version': '3'}):
                do_something()

        :param default_config: Dict of charm settings to set on completion
        :type default_config: dict
        :param alternate_config: Dict of charm settings to change to
        :type alternate_config: dict
        :param application_name: String application name for use when called
                                 by a charm under test other than the object's
                                 application.
        :type application_name: str
        """
        if not application_name:
            application_name = self.application_name

        # we need to compare config values to what is already applied before
        # attempting to set them.  otherwise the model will behave differently
        # than we would expect while waiting for completion of the change
        app_config = self.config_current(application_name,
                                         keys=alternate_config.keys())

        if all(item in app_config.items()
               for item in alternate_config.items()):
            logging.debug('alternate_config equals what is already applied '
                          'config')
            yield
            if default_config == alternate_config:
                logging.debug('default_config also equals what is already '
                              'applied config')
                return
            logging.debug('alternate_config already set, and default_config '
                          'needs to be applied before return')
        else:
            logging.debug(
                'Changing charm setting to {}'.format(alternate_config))
            model.set_application_config(
                application_name,
                self._stringed_value_config(alternate_config),
                model_name=self.model_name)

            logging.debug('Waiting for units to execute config-changed hook')
            model.wait_for_agent_status(model_name=self.model_name)

            logging.debug('Waiting for units to reach target states')
            model.wait_for_application_states(model_name=self.model_name,
                                              states=self.test_config.get(
                                                  'target_deploy_status', {}))
            # TODO: Optimize with a block on a specific application until idle.
            model.block_until_all_units_idle()

            yield

        logging.debug('Restoring charm setting to {}'.format(default_config))
        model.set_application_config(
            application_name,
            self._stringed_value_config(default_config),
            model_name=self.model_name)

        logging.debug('Waiting for units to reach target states')
        model.wait_for_application_states(model_name=self.model_name,
                                          states=self.test_config.get(
                                              'target_deploy_status', {}))
        # TODO: Optimize with a block on a specific application until idle.
        model.block_until_all_units_idle()
Beispiel #11
0
    def config_change(self, default_config, alternate_config):
        """Run change config tests.

        Change config to `alternate_config`, wait for idle workload status,
        yield, return config to `default_config` and wait for idle workload
        status before return from function.

        Example usage:
            with self.config_change({'preferred-api-version': '2'},
                                    {'preferred-api-version': '3'}):
                do_something()

        :param default_config: Dict of charm settings to set on completion
        :type default_config: dict
        :param alternate_config: Dict of charm settings to change to
        :type alternate_config: dict
        """
        # we need to compare config values to what is already applied before
        # attempting to set them.  otherwise the model will behave differently
        # than we would expect while waiting for completion of the change
        _app_config = model.get_application_config(self.application_name)
        app_config = {}
        # convert the more elaborate config structure from libjuju to something
        # we can compare to what the caller supplies to this function
        for k in alternate_config.keys():
            # note that conversion to string for all values is due to
            # attempting to set any config with other types lead to Traceback
            app_config[k] = str(_app_config.get(k, {}).get('value', ''))
        if all(item in app_config.items()
               for item in alternate_config.items()):
            logging.debug('alternate_config equals what is already applied '
                          'config')
            yield
            if default_config == alternate_config:
                logging.debug('default_config also equals what is already '
                              'applied config')
                return
            logging.debug('alternate_config already set, and default_config '
                          'needs to be applied before return')
        else:
            logging.debug(
                'Changing charm setting to {}'.format(alternate_config))
            model.set_application_config(self.application_name,
                                         alternate_config,
                                         model_name=self.model_name)

            logging.debug('Waiting for units to execute config-changed hook')
            model.wait_for_agent_status(model_name=self.model_name)

            logging.debug('Waiting for units to reach target states')
            model.wait_for_application_states(model_name=self.model_name,
                                              states=self.test_config.get(
                                                  'target_deploy_status', {}))
            # TODO: Optimize with a block on a specific application until idle.
            model.block_until_all_units_idle()

            yield

        logging.debug('Restoring charm setting to {}'.format(default_config))
        model.set_application_config(self.application_name,
                                     default_config,
                                     model_name=self.model_name)

        logging.debug('Waiting for units to reach target states')
        model.wait_for_application_states(model_name=self.model_name,
                                          states=self.test_config.get(
                                              'target_deploy_status', {}))
        # TODO: Optimize with a block on a specific application until idle.
        model.block_until_all_units_idle()