def test_make_g5k(self): "Tests the creation of G5k provider" from enos.provider.g5k import G5k self.assertIsInstance(xenos.make_provider(self.__provider_env('g5k')), G5k) self.assertIsInstance( xenos.make_provider(self.__provider_env_ext('g5k')), G5k)
def test_make_static(self): "Tests the creation of Static provider" from enos.provider.static import Static self.assertIsInstance( xenos.make_provider(self.__provider_env('static')), Static) self.assertIsInstance( xenos.make_provider(self.__provider_env_ext('static')), Static)
def test_make_vbox(self): "Tests the creation of Vbox provider" from enos.provider.enos_vagrant import Enos_vagrant self.assertIsInstance( xenos.make_provider(self.__provider_env('vagrant')), Enos_vagrant) self.assertIsInstance( xenos.make_provider(self.__provider_env_ext('vagrant')), Enos_vagrant)
def destroy(env=None, **kwargs): hard = kwargs['--hard'] if hard: logging.info('Destroying all the resources') provider_conf = env['config']['provider'] provider = make_provider(provider_conf) provider.destroy(env) else: command = ['destroy', '--yes-i-really-really-mean-it'] if kwargs['--include-images']: command.append('--include-images') kolla_kwargs = { '--': True, '--env': kwargs['--env'], '-v': kwargs['-v'], '<command>': command, '--silent': kwargs['--silent'], 'kolla': True } options = {"enos_action": "destroy"} up_playbook = os.path.join(ANSIBLE_DIR, 'enos.yml') inventory_path = os.path.join(env['resultdir'], 'multinode') # Destroying enos resources run_ansible([up_playbook], inventory_path, extra_vars=options) # Destroying kolla resources _kolla(env=env, **kolla_kwargs)
def up(config, config_file=None, env=None, **kwargs): logging.debug('phase[up]: args=%s' % kwargs) # Calls the provider and initialise resources provider_conf = config['provider'] provider = make_provider(provider_conf) # Applying default configuration config = load_config(config, provider.default_config()) env['config'] = config env['config_file'] = config_file logging.debug("Loaded config: %s", config) rsc, networks = \ provider.init(env['config'], kwargs['--force-deploy']) env['rsc'] = rsc env['networks'] = networks logging.debug("Provider ressources: %s", env['rsc']) logging.debug("Provider network information: %s", env['networks']) # Generates inventory for ansible/kolla inventory = os.path.join(env['resultdir'], 'multinode') inventory_conf = env['config'].get('inventory') if not inventory_conf: logging.debug("No inventory specified, using the sample.") base_inventory = os.path.join(INVENTORY_DIR, 'inventory.sample') else: base_inventory = seekpath(inventory_conf) generate_inventory(env['rsc'], env['networks'], base_inventory, inventory) logging.info('Generates inventory %s' % inventory) env['inventory'] = inventory # Set variables required by playbooks of the application vip_pool = get_vip_pool(networks) env['config'].update({ 'vip': pop_ip(vip_pool), 'registry_vip': pop_ip(vip_pool), 'influx_vip': pop_ip(vip_pool), 'grafana_vip': pop_ip(vip_pool), 'resultdir': env['resultdir'], 'rabbitmq_password': "******", 'database_password': "******" }) options = {} options.update(env['config']) enos_action = "pull" if kwargs.get("--pull") else "deploy" options.update(enos_action=enos_action) # Runs playbook that initializes resources (eg, # installs the registry, install monitoring tools, ...) up_playbook = os.path.join(ANSIBLE_DIR, 'enos.yml') run_ansible([up_playbook], env['inventory'], extra_vars=options, tags=kwargs['--tags'])
def destroy_infra(env: elib.Environment): """Destroy resources acquired on the testbed Args: env: State for the current experiment. Read from the env: config: Configuration (as a dict) """ provider_conf = eget(env, 'config')['provider'] provider = make_provider(provider_conf) logging.info(f'Destroying resources acquired on {provider}...') provider.destroy(env)
def test_make_unexist(self): "Tests the raise of error for unknown/unloaded provider" with self.assertRaises(EnosUnknownProvider): xenos.make_provider(self.__provider_env('unexist'))
def new(provider_name: str, output_path: Path): '''Create a basic configuration file (reservation.yaml ). Create the configuration file for `provider_name` at `outpout_path`. Args: provider_name: Name of the provider, e.g., g5k, vagrant:libvirt, ... output_path: Path to write the configuration file to. Raises: EnosUnknownProvider: if the provider name does not match a known provider. FileExistsError: if the output_path points to a file that already exists. ''' # Get the provider and backend names, e.g. (g5k, None) or (vagrant, # virtualbox) provider, backend = get_provider_and_backend_names(provider_name) # Options for the reservation.yaml.j2 template provider_conf = make_provider(provider).default_config() provider_required_keys = ['type'] resources_conf = None registry_conf = None # Refine options based on the provider if provider == 'g5k': resources_conf = G5K_RSC registry_conf = G5K_EXTERNAL_REG provider_required_keys += ['walltime', 'job_name'] elif provider == 'vagrant': provider_conf.update(backend=backend) resources_conf = VAGRANT_RSC registry_conf = INTERNAL_REG provider_required_keys.append('backend') elif provider == 'chameleonkvm': provider_conf.update( key_name='<set a Nova SSH key (see `openstack keypair list`)>') registry_conf = INTERNAL_REG resources_conf = CHAM_KVM_RSC provider_required_keys.append('key_name') elif provider == 'chameleonbaremetal': provider_conf.update( key_name='<set a Nova SSH key (see `openstack keypair list`)>') registry_conf = INTERNAL_REG resources_conf = CHAM_BARE_RSC provider_required_keys += ['key_name', 'walltime'] elif provider == 'openstack': provider_conf.update( user='******', key_name='<set a Nova SSH key (see `openstack keypair list`)>', image='<set a Glance image (see `openstack image list`)>') registry_conf = INTERNAL_REG resources_conf = OS_RSC provider_required_keys += ['user', 'key_name', 'image'] elif provider == 'vmong5k': resources_conf = VMONG5K_RSC registry_conf = INTERNAL_REG provider_required_keys += ['walltime', 'job_name'] elif provider == 'static': resources_conf = STATIC_RSC registry_conf = INTERNAL_REG LOGGER.debug(f'Generating {output_path} file with ' f'provider conf {provider_conf}, ' f'registry conf {registry_conf}, and ' f'resource conf {resources_conf} ...') # Render the reservation.yaml.j2 template with open(Path(C.TEMPLATE_DIR) / 'reservation.yaml.j2') as jinja_f,\ open(output_path, mode='x') as res_f: template = jinja2.Template(jinja_f.read(), autoescape=False) res_f.write(template.render( provider=dump(provider_conf, provider_required_keys), resources=yaml.dump(resources_conf), registry=yaml.dump(registry_conf), kolla_ansible=kolla.KOLLA_PKG))