def _copy_terraform_files(self):
     shutil.copy(get_resource_path(
         'terraform/aws-osx-cli-test.tf'),
         self.tmpdir / 'aws-osx-cli-test.tf')
     shutil.copy(get_resource_path(
         'terraform/scripts/osx-cli-test.sh'),
         self.tmpdir / 'scripts/osx-cli-test.sh')
 def _copy_terraform_files(self):
     shutil.copy(get_resource_path(
             'terraform/openstack-linux-cli-test.tf'),
             self.tmpdir / 'openstack-linux-cli-test.tf')
     shutil.copy(get_resource_path(
             'terraform/scripts/linux-cli-test.sh'),
             self.tmpdir / 'scripts/linux-cli-test.sh')
Exemplo n.º 3
0
 def _copy_terraform_files(self):
     shutil.copy(
         get_resource_path('terraform/openstack-windows-cli-test.tf'),
         self.tmpdir / 'openstack-windows-cli-test.tf')
     shutil.copy(
         get_resource_path('terraform/scripts/windows-userdata.ps1'),
         self.tmpdir / 'scripts/windows-userdata.ps1')
 def _copy_terraform_files(self):
     shutil.copy(get_resource_path(
             'terraform/openstack-windows-cli-test.tf'),
             self.tmpdir / 'openstack-windows-cli-test.tf')
     shutil.copy(get_resource_path(
             'terraform/scripts/windows-userdata.ps1'),
                 self.tmpdir / 'scripts/windows-userdata.ps1')
def _test_agent(agent_type, cfy, manager, attributes):
    agent_blueprints = {
        'a3_2': 'agent/3-2-agent-blueprint/3-2-agent-mispelled-blprint.yaml',
        'ssh': 'agent/ssh-agent-blueprint/ssh-agent-blueprint.yaml',
    }

    blueprint_path = util.get_resource_path(agent_blueprints[agent_type])

    tenant = prepare_and_get_test_tenant(
        'agent_{}'.format(agent_type),
        manager,
        cfy,
    )
    blueprint_id = deployment_id = agent_type

    with set_client_tenant(manager, tenant):
        manager.client.blueprints.upload(blueprint_path, blueprint_id)
        manager.client.deployments.create(
            deployment_id, blueprint_id, inputs={
                'ip_address': manager.ip_address,
                'user': attributes.default_linux_username,
                'private_key_path': manager.remote_private_key_path
            }, skip_plugins_validation=True)
    try:
        cfy.executions.start.install(['-d', deployment_id,
                                      '--tenant-name', tenant])
    finally:
        cfy.executions.start.uninstall(['-d', deployment_id,
                                        '--tenant-name', tenant])
def _test_userdata_agent(cfy, manager, inputs, tenant):
    blueprint_id = deployment_id = 'userdata{0}'.format(time.time())
    blueprint_path = util.get_resource_path(
        'agent/userdata-agent-blueprint/userdata-agent-blueprint.yaml')

    with set_client_tenant(manager, tenant):
        manager.client.blueprints.upload(blueprint_path, blueprint_id)
        manager.client.deployments.create(
            deployment_id,
            blueprint_id,
            inputs=inputs,
            skip_plugins_validation=True)

    cfy.executions.start.install(['-d', deployment_id,
                                  '--tenant-name', tenant])

    try:
        with set_client_tenant(manager, tenant):
            assert {
                'MY_ENV_VAR': 'MY_ENV_VAR_VALUE',
                'file_content': EXPECTED_FILE_CONTENT
            } == manager.client.deployments.outputs.get(deployment_id).outputs
    finally:
        cfy.executions.start.uninstall(['-d', deployment_id,
                                        '--tenant-name', tenant])
def _test_agent(agent_type, cfy, manager, attributes):
    agent_blueprints = {
        'a3_2': 'agent/3-2-agent-blueprint/3-2-agent-mispelled-blprint.yaml',
        'ssh': 'agent/ssh-agent-blueprint/ssh-agent-blueprint.yaml',
    }

    blueprint_path = util.get_resource_path(agent_blueprints[agent_type])

    tenant = prepare_and_get_test_tenant(
        'agent_{}'.format(agent_type),
        manager,
        cfy,
    )
    blueprint_id = deployment_id = agent_type

    with set_client_tenant(manager, tenant):
        manager.client.blueprints.upload(blueprint_path, blueprint_id)
        manager.client.deployments.create(
            deployment_id, blueprint_id, inputs={
                'ip_address': manager.ip_address,
                'user': attributes.default_linux_username,
                'private_key_path': manager.remote_private_key_path
            }, skip_plugins_validation=True)
    try:
        cfy.executions.start.install(['-d', deployment_id,
                                      '--tenant-name', tenant])
    finally:
        cfy.executions.start.uninstall(['-d', deployment_id,
                                        '--tenant-name', tenant])
    def bootstrap(self, enter_sanity_mode=True, upload_license=False):
        manager_install_rpm = \
            ATTRIBUTES.cloudify_manager_install_rpm_url.strip() or \
            util.get_manager_install_rpm_url()

        install_config = self._create_config_file(upload_license)
        install_rpm_file = 'cloudify-manager-install.rpm'
        with self.ssh() as fabric_ssh:
            fabric_ssh.run(
                'curl -S {0} -o {1}'.format(
                    manager_install_rpm,
                    install_rpm_file
                )
            )
            fabric_ssh.sudo('yum install -y {0}'.format(install_rpm_file))
            fabric_ssh.put(
                install_config,
                '/etc/cloudify/config.yaml'
            )
            if upload_license:
                fabric_ssh.put(
                    util.get_resource_path('test_valid_paying_license.yaml'),
                    '/tmp/test_valid_paying_license.yaml'
                )
            fabric_ssh.run('cfy_manager install')
        if enter_sanity_mode:
            self.enter_sanity_mode()
def _test_userdata_agent(cfy, manager, inputs, tenant):
    blueprint_id = deployment_id = 'userdata{0}'.format(time.time())
    blueprint_path = util.get_resource_path(
        'agent/userdata-agent-blueprint/userdata-agent-blueprint.yaml')

    with set_client_tenant(manager, tenant):
        manager.client.blueprints.upload(blueprint_path, blueprint_id)
        manager.client.deployments.create(
            deployment_id,
            blueprint_id,
            inputs=inputs,
            skip_plugins_validation=True)

    cfy.executions.start.install(['-d', deployment_id,
                                  '--tenant-name', tenant])

    try:
        with set_client_tenant(manager, tenant):
            assert {
                'MY_ENV_VAR': 'MY_ENV_VAR_VALUE',
                'file_content': EXPECTED_FILE_CONTENT
            } == manager.client.deployments.outputs.get(deployment_id).outputs
    finally:
        cfy.executions.start.uninstall(['-d', deployment_id,
                                        '--tenant-name', tenant])
def _test_agent_alive_after_reboot(cfy, manager, attributes, os_name,
                                   suffix=None):
    suffix = suffix or os_name
    os_blueprints = {
        'centos_7': 'agent/reboot-vm-blueprint/reboot-unix-vm-blueprint.yaml',
        'ubuntu_14_04': (
            'agent/reboot-vm-blueprint/reboot-unix-vm-blueprint.yaml'
        ),
        'windows_2012': (
            'agent/reboot-vm-blueprint/reboot-winrm-vm-blueprint.yaml'
        ),
    }
    blueprint_name = os_blueprints[os_name]

    tenant = prepare_and_get_test_tenant(suffix, manager, cfy)

    inputs = {
        'image': attributes['{os}_image_name'.format(os=os_name)],
        'flavor': attributes['medium_flavor_name'],
        'user': attributes['{os}_username'.format(os=os_name)],
        'network_name': attributes['network_name'],
        'private_key_path': manager.remote_private_key_path,
        'keypair_name': attributes['keypair_name'],
    }

    blueprint_path = util.get_resource_path(blueprint_name)
    inputs['value'] = os_name
    blueprint_id = deployment_id = os_name

    with set_client_tenant(manager, tenant):
        manager.client.blueprints.upload(blueprint_path, blueprint_id)
        manager.client.deployments.create(
            deployment_id,
            blueprint_id,
            inputs=inputs,
            skip_plugins_validation=True)

    try:
        cfy.executions.start.install(['-d', deployment_id,
                                      '--tenant-name', tenant])
        cfy.executions.start.execute_operation(
            deployment_id=deployment_id,
            parameters={
                'operation': 'cloudify.interfaces.reboot_test.reboot',
                'node_ids': ['host']
            },
            tenant_name=tenant)
    finally:
        cfy.executions.start.uninstall(['-d', deployment_id,
                                        '--tenant-name', tenant])
    with set_client_tenant(manager, tenant):
        app = manager.client.node_instances.list(
            node_id='application',
            deployment_id=deployment_id,
        )[0]
    assert os_name == app.runtime_properties['value']
def _test_agent_alive_after_reboot(cfy, manager, attributes, os_name,
                                   suffix=None):
    suffix = suffix or os_name
    os_blueprints = {
        'centos_7': 'agent/reboot-vm-blueprint/reboot-unix-vm-blueprint.yaml',
        'ubuntu_14_04': (
            'agent/reboot-vm-blueprint/reboot-unix-vm-blueprint.yaml'
        ),
        'windows_2012': (
            'agent/reboot-vm-blueprint/reboot-winrm-vm-blueprint.yaml'
        ),
    }
    blueprint_name = os_blueprints[os_name]

    tenant = prepare_and_get_test_tenant(suffix, manager, cfy)

    inputs = {
        'image': attributes['{os}_image_name'.format(os=os_name)],
        'flavor': attributes['medium_flavor_name'],
        'user': attributes['{os}_username'.format(os=os_name)],
        'network_name': attributes['network_name'],
        'private_key_path': manager.remote_private_key_path,
        'keypair_name': attributes['keypair_name'],
    }

    blueprint_path = util.get_resource_path(blueprint_name)
    inputs['value'] = os_name
    blueprint_id = deployment_id = os_name

    with set_client_tenant(manager, tenant):
        manager.client.blueprints.upload(blueprint_path, blueprint_id)
        manager.client.deployments.create(
            deployment_id,
            blueprint_id,
            inputs=inputs,
            skip_plugins_validation=True)

    try:
        cfy.executions.start.install(['-d', deployment_id,
                                      '--tenant-name', tenant])
        cfy.executions.start.execute_operation(
            deployment_id=deployment_id,
            parameters={
                'operation': 'cloudify.interfaces.reboot_test.reboot',
                'node_ids': ['host']
            },
            tenant_name=tenant)
    finally:
        cfy.executions.start.uninstall(['-d', deployment_id,
                                        '--tenant-name', tenant])
    with set_client_tenant(manager, tenant):
        app = manager.client.node_instances.list(
            node_id='application',
            deployment_id=deployment_id,
        )[0]
    assert os_name == app.runtime_properties['value']
def _test_windows_common(
        cfy,
        manager,
        attributes,
        blueprint_path,
        inputs,
        os_name,
        tenant,
        deployment_id_prefix):
    user = attributes.windows_2012_username
    if not tenant:
        tenant = prepare_and_get_test_tenant(
            '{0}_{1}'.format(deployment_id_prefix, os_name),
            manager,
            cfy
        )

    effective_inputs = {
        'image': attributes.windows_2012_image_name,
        'flavor': attributes.medium_flavor_name,
        'user': user,
        'network_name': attributes.network_name,
        'private_key_path': manager.remote_private_key_path,
        'keypair_name': attributes.keypair_name,
    }

    if inputs:
        effective_inputs.update(inputs)

    blueprint_id = deployment_id = '{0}_{1}'.format(
        deployment_id_prefix, time.time())
    blueprint_path = util.get_resource_path(blueprint_path)

    with set_client_tenant(manager, tenant):
        manager.client.blueprints.upload(blueprint_path, blueprint_id)
        manager.client.deployments.create(
            deployment_id,
            blueprint_id,
            inputs=effective_inputs,
            skip_plugins_validation=True)

    cfy.executions.start.install(['-d', deployment_id,
                                  '--tenant-name', tenant])

    try:
        cfy.executions.start.execute_operation(
            deployment_id=deployment_id,
            parameters={
                'operation': 'test.interface.test',
                'node_ids': ['test_app']
            },
            tenant_name=tenant)
    finally:
        cfy.executions.start.uninstall(['-d', deployment_id,
                                        '--tenant-name', tenant])
def _test_windows_common(
        cfy,
        manager,
        attributes,
        blueprint_path,
        inputs,
        os_name,
        tenant,
        deployment_id_prefix):
    user = attributes.windows_2012_username
    if not tenant:
        tenant = prepare_and_get_test_tenant(
            '{0}_{1}'.format(deployment_id_prefix, os_name),
            manager,
            cfy
        )

    effective_inputs = {
        'image': attributes.windows_2012_image_name,
        'flavor': attributes.medium_flavor_name,
        'user': user,
        'network_name': attributes.network_name,
        'private_key_path': manager.remote_private_key_path,
        'keypair_name': attributes.keypair_name,
    }

    if inputs:
        effective_inputs.update(inputs)

    blueprint_id = deployment_id = '{0}_{1}'.format(
        deployment_id_prefix, time.time())
    blueprint_path = util.get_resource_path(blueprint_path)

    with set_client_tenant(manager, tenant):
        manager.client.blueprints.upload(blueprint_path, blueprint_id)
        manager.client.deployments.create(
            deployment_id,
            blueprint_id,
            inputs=effective_inputs,
            skip_plugins_validation=True)

    cfy.executions.start.install(['-d', deployment_id,
                                  '--tenant-name', tenant])

    try:
        cfy.executions.start.execute_operation(
            deployment_id=deployment_id,
            parameters={
                'operation': 'test.interface.test',
                'node_ids': ['test_app']
            },
            tenant_name=tenant)
    finally:
        cfy.executions.start.uninstall(['-d', deployment_id,
                                        '--tenant-name', tenant])
    def test_winrm_agent(self):

        self.blueprint_yaml = util.get_resource_path(
            'agent/winrm-agent-blueprint/winrm-agent-blueprint.yaml')
        self.upload_deploy_and_execute_install(
            inputs={
                'image': self.env.windows_image_name,
                'flavor': self.env.medium_flavor_id
            }
        )
        self.execute_uninstall()
    def test_ssh_agent(self):

        self.blueprint_yaml = util.get_resource_path(
            'agent/ssh-agent-blueprint/ssh-agent-blueprint.yaml')
        self.upload_deploy_and_execute_install(
            inputs={
                'image': self.env.ubuntu_trusty_image_id,
                'flavor': self.env.small_flavor_id
            }
        )
        self.execute_uninstall()
    def additional_setup(self):
        if self.package_parameter_name not in os.environ:
            raise ValueError(
                '{0} environment variable not set'
                .format(self.package_parameter_name))

        blueprint_filename = self.local_env_blueprint_file_name
        relative_blueprint_path = os.path.join('blueprints',
                                               'cli',
                                               blueprint_filename)
        blueprint_path = util.get_resource_path(relative_blueprint_path)

        self.test_id = 'stest-{0}'.format(
            time.strftime("%Y%m%d-%H%M"))
        self.prefix = '{0}-cli-host'.format(self.test_id)
        self.bootstrap_prefix = 'cloudify-{0}'.format(self.test_id)

        self.branch = os.environ.get('BRANCH_NAME_CORE', 'master')
        self.logger.info('Using branch/tag: {0}'.format(self.branch))

        self.logger.info('initialize local env for running the '
                         'blueprint that starts a vm')
        self.local_env = local.init_env(
            blueprint_path,
            inputs=self.local_env_inputs,
            name=self._testMethodName,
            ignored_modules=cli_constants.IGNORED_LOCAL_WORKFLOW_MODULES)

        self.logger.info('Starting vm to install CLI package on it later on')
        self.addCleanup(self.cleanup)
        self.local_env.execute('install',
                               task_retries=40,
                               task_retry_interval=30)

        self.get_local_env_outputs()
        self.logger.info('Outputs: {0}'.format(self.local_env.outputs()))

        self.centos_client_env = {
            'timeout': 30,
            'user': self.client_user,
            'key_filename': self.local_env_inputs['key_pair_path'],
            'host_string': self.public_ip_address,
            'connection_attempts': 10,
            'abort_on_prompts': True
        }

        self.verify_connection()
        # Since different IAAS providers enable some default DNS which enables
        # internet access, by this call we make sure that all of the tests
        # begin with no dns based internet connection. In online tests, the
        # dns is being set by the dns() context manager.
        self.go_offline(self.centos_client_env)
Exemplo n.º 17
0
def web_app(cfy, manager, attributes, ssh_key, logger, tmpdir):
    hw = centos_hello_world(cfy,
                            manager,
                            attributes,
                            ssh_key,
                            logger,
                            tmpdir)
    hw.blueprint_file = util.get_resource_path(
        'blueprints/deployment_proxy/web_app.yaml'
    )
    hw.inputs.clear()
    yield hw
    hw.cleanup()
Exemplo n.º 18
0
def vm_infrastructure(cfy, manager, attributes, ssh_key, logger, tmpdir):
    hw = centos_hello_world(cfy,
                            manager,
                            attributes,
                            ssh_key,
                            logger,
                            tmpdir)
    hw.blueprint_file = util.get_resource_path(
        'blueprints/deployment_proxy/vm_infrastructure.yaml'
    )
    hw.blueprint_id = 'os_infra'
    hw.deployment_id = 'os_infra'
    yield hw
    hw.cleanup()
 def _test_verify_wrong_cert(self):
     cert_path = os.path.join(self.workdir, 'wrong.cert')
     key_path = os.path.join(self.workdir, 'wrong.key')
     self.create_self_signed_certificate(cert_path, key_path, 'test')
     client = CloudifyClient(host=self.env.management_ip,
                             port=constants.SECURED_REST_PORT,
                             protocol=constants.SECURED_PROTOCOL,
                             headers=util.get_auth_header(
                                 username=TEST_CFY_USERNAME,
                                 password=TEST_CFY_PASSWORD),
                             cert=util.get_resource_path(cert_path),
                             trust_all=False)
     try:
         client.manager.get_status()
         self.fail('certification verification expected to fail')
     except SSLError as e:
         self.assertIn('certificate verify failed', str(e.message))
def hostpool(cfy, manager, attributes, ssh_key, logger, tmpdir):
    tenant = util.prepare_and_get_test_tenant('hostpool', manager, cfy)
    hp = HostPoolExample(cfy, manager, attributes, ssh_key, logger, tmpdir,
                         tenant=tenant, suffix='hostpool')
    hp.blueprint_file = util.get_resource_path('hostpool/service-blueprint.yaml')  # noqa
    hp.skip_plugins_validation = True

    # verification is unrolled here because we want to validate and yield
    # the service for further testing before uninstalling it
    hp.upload_blueprint()
    hp.create_deployment()
    hp.install()
    hp.verify_installation()
    yield hp
    hp.uninstall()
    hp.delete_deployment()
    hp.cleanup()
 def _test_verify_wrong_cert(self):
     cert_path = os.path.join(self.workdir, 'wrong.cert')
     key_path = os.path.join(self.workdir, 'wrong.key')
     self.create_self_signed_certificate(cert_path, key_path, 'test')
     client = CloudifyClient(
         host=self.env.management_ip,
         port=constants.SECURED_REST_PORT,
         protocol=constants.SECURED_PROTOCOL,
         headers=util.get_auth_header(username=TEST_CFY_USERNAME,
                                      password=TEST_CFY_PASSWORD),
         cert=util.get_resource_path(cert_path),
         trust_all=False)
     try:
         client.manager.get_status()
         self.fail('certification verification expected to fail')
     except SSLError as e:
         self.assertIn('certificate verify failed', str(e.message))
Exemplo n.º 22
0
 def _assert_plugins_installed(self):
     manager_key_path = util.get_actual_keypath(
         self.env, self.env.management_key_path)
     local_script_path = util.get_resource_path(
         'scripts/test_rest_plugins.sh')
     remote_script_path = ('/home/{0}/test_rest_plugins.sh'.format(
         self.env.management_user_name))
     with fabric_api.settings(timeout=30,
                              user=self.env.management_user_name,
                              key_filename=manager_key_path,
                              host_string=self.cfy.get_management_ip(),
                              warn_only=False):
         fabric_api.put(local_script_path, remote_script_path)
         output = fabric_api.run(
             'chmod +x {0} && {0}'.format(remote_script_path))
     # This tells us that plugin-template was successfully installed
     self.assertIn('imported_plugin_tasks', output)
     # This tells us that mock-rest-plugin was successfully installed
     self.assertIn('mock_attribute_value', output)
 def _assert_plugins_installed(self):
     manager_key_path = util.get_actual_keypath(
         self.env, self.env.management_key_path)
     local_script_path = util.get_resource_path(
         'scripts/test_rest_plugins.sh')
     remote_script_path = ('/home/{0}/test_rest_plugins.sh'
                           .format(self.env.management_user_name))
     with fabric_api.settings(
             timeout=30,
             user=self.env.management_user_name,
             key_filename=manager_key_path,
             host_string=self.cfy.get_management_ip(),
             warn_only=False):
         fabric_api.put(local_script_path, remote_script_path)
         output = fabric_api.run(
             'chmod +x {0} && {0}'.format(remote_script_path))
     # This tells us that plugin-template was successfully installed
     self.assertIn('imported_plugin_tasks', output)
     # This tells us that mock-rest-plugin was successfully installed
     self.assertIn('mock_attribute_value', output)
    def _test_agent_alive_after_reboot(self, blueprint, inputs):

        self.blueprint_yaml = util.get_resource_path(blueprint)
        value = str(uuid.uuid4())
        inputs['value'] = value
        deployment_id = self.test_id
        self.upload_deploy_and_execute_install(
            deployment_id=deployment_id,
            inputs=inputs)
        self.cfy.executions.start(
            'execute_operation',
            deployment_id=deployment_id,
            parameters={
                'operation': 'cloudify.interfaces.reboot_test.reboot',
                'node_ids': ['host']
            },
            include_logs=True)
        self.execute_uninstall(deployment_id=deployment_id)
        app = self.client.node_instances.list(node_id='application',
                                              deployment_id=deployment_id)[0]
        self.assertEquals(value, app.runtime_properties['value'])
 def _test_userdata_agent(self, image, flavor, user, os_family,
                          userdata, file_path, install_method,
                          name=None):
     deployment_id = 'userdata{0}'.format(time.time())
     self.blueprint_yaml = util.get_resource_path(
         'agent/userdata-agent-blueprint/userdata-agent-blueprint.yaml')
     self.upload_deploy_and_execute_install(
         deployment_id=deployment_id,
         inputs={
             'image': image,
             'flavor': flavor,
             'agent_user': user,
             'os_family': os_family,
             'userdata': userdata,
             'file_path': file_path,
             'install_method': install_method,
             'name': name
         }
     )
     self.assert_outputs({'MY_ENV_VAR': 'MY_ENV_VAR_VALUE',
                          'file_content': self.expected_file_content},
                         deployment_id=deployment_id)
     self.execute_uninstall(deployment_id=deployment_id)
    def create(self):
        """Creates the infrastructure for a Cloudify manager.

        The credentials file and private key file for SSHing
        to provisioned VMs are uploaded to the server."""
        self._logger.info('Creating image based cloudify instances: '
                          '[number_of_instances=%d]', len(self.instances))

        terraform_template_file = self._tmpdir / 'openstack-vm.tf'

        input_file = util.get_resource_path(
            'terraform/{0}'.format(self._tf_template)
        )
        with open(input_file, 'r') as f:
            tf_template = f.read()

        output = jinja2.Template(tf_template).render(self._template_inputs)

        terraform_template_file.write_text(output)

        self._terraform_inputs_file.write_text(json.dumps({
            'resource_suffix': str(uuid.uuid4()),
            'public_key_path': self._ssh_key.public_key_path,
            'private_key_path': self._ssh_key.private_key_path,
            'flavor': self._get_server_flavor()
        }, indent=2))

        try:
            with self._tmpdir:
                self._terraform.apply(['-var-file',
                                       self._terraform_inputs_file])
                outputs = util.AttributesDict(
                    {k: v['value'] for k, v in yaml.safe_load(
                        self._terraform.output(
                            ['-json']).stdout).items()})
            self._attributes.update(outputs)

            self._update_instances_list(outputs)

            if self.preconfigure_callback:
                self.preconfigure_callback(self.instances)

            self._bootstrap_managers()

            for instance in self.instances:
                instance.verify_services_are_running()
                instance.upload_necessary_files()
                if instance.upload_plugins:
                    instance.upload_plugin(
                        self._attributes.default_openstack_plugin)

            self._logger.info('Test hosts successfully created!')

        except Exception as e:
            self._logger.error(
                'Error creating image based hosts: %s', e)
            try:
                self.destroy()
            except sh.ErrorReturnCode as ex:
                self._logger.error('Error on terraform destroy: %s', ex)
            raise
 def _create_sample_wheel(self):
     src = util.get_resource_path('plugins/{0}'.format(TEST_PACKAGE_NAME))
     wagon_client = Wagon(src)
     return wagon_client.create(
         archive_destination_dir=tempfile.mkdtemp(dir=self.workdir),
         force=True)
Exemplo n.º 28
0
    def create(self):
        """Creates the infrastructure for a Cloudify manager.

        The credentials file and private key file for SSHing
        to provisioned VMs are uploaded to the server."""
        self._logger.info(
            'Creating image based cloudify instances: '
            '[number_of_instances=%d]', len(self.instances))

        terraform_template_file = self._tmpdir / 'openstack-vm.tf'

        input_file = util.get_resource_path('terraform/{0}'.format(
            self._tf_template))
        with open(input_file, 'r') as f:
            tf_template = f.read()

        output = jinja2.Template(tf_template).render(self._template_inputs)

        terraform_template_file.write_text(output)

        self._terraform_inputs_file.write_text(
            json.dumps(
                {
                    'resource_suffix': str(uuid.uuid4()),
                    'public_key_path': self._ssh_key.public_key_path,
                    'private_key_path': self._ssh_key.private_key_path,
                    'flavor': self._get_server_flavor()
                },
                indent=2))

        try:
            with self._tmpdir:
                self._terraform.apply(
                    ['-var-file', self._terraform_inputs_file])
                outputs = util.AttributesDict({
                    k: v['value']
                    for k, v in yaml.safe_load(
                        self._terraform.output(['-json']).stdout).items()
                })
            self._attributes.update(outputs)

            self._update_instances_list(outputs)

            if self.preconfigure_callback:
                self.preconfigure_callback(self.instances)

            self._bootstrap_managers()

            for instance in self.instances:
                instance.verify_services_are_running()
                instance.upload_necessary_files()
                if instance.upload_plugins:
                    instance.upload_plugin(
                        self._attributes.default_openstack_plugin)

            self._logger.info('Test hosts successfully created!')

        except Exception as e:
            self._logger.error('Error creating image based hosts: %s', e)
            try:
                self.destroy()
            except sh.ErrorReturnCode as ex:
                self._logger.error('Error on terraform destroy: %s', ex)
            raise
Exemplo n.º 29
0
 def _copy_terraform_files(self):
     shutil.copy(get_resource_path('terraform/aws-osx-cli-test.tf'),
                 self.tmpdir / 'aws-osx-cli-test.tf')
     shutil.copy(get_resource_path('terraform/scripts/osx-cli-test.sh'),
                 self.tmpdir / 'scripts/osx-cli-test.sh')
Exemplo n.º 30
0
 def _copy_terraform_files(self):
     shutil.copy(get_resource_path('terraform/openstack-linux-cli-test.tf'),
                 self.tmpdir / 'openstack-linux-cli-test.tf')
     shutil.copy(get_resource_path('terraform/scripts/linux-cli-test.sh'),
                 self.tmpdir / 'scripts/linux-cli-test.sh')
Exemplo n.º 31
0
    def create(self):
        """Creates the OpenStack infrastructure for a Cloudify manager.

        The openstack credentials file and private key file for SSHing
        to provisioned VMs are uploaded to the server."""
        self._logger.info(
            'Creating an image based cloudify cluster '
            '[number_of_managers=%d]', self._number_of_managers)

        openstack_config_file = self._tmpdir / 'openstack_config.json'
        openstack_config_file.write_text(
            json.dumps(
                {
                    'username':
                    os.environ['OS_USERNAME'],
                    'password':
                    os.environ['OS_PASSWORD'],
                    'tenant_name':
                    os.environ.get('OS_TENANT_NAME',
                                   os.environ['OS_PROJECT_NAME']),
                    'auth_url':
                    os.environ['OS_AUTH_URL']
                },
                indent=2))

        terraform_template_file = self._tmpdir / 'openstack-vm.tf'

        input_file = util.get_resource_path(
            'terraform/openstack-vm.tf.template')
        with open(input_file, 'r') as f:
            terraform_template = f.read()

        output = jinja2.Template(terraform_template).render(
            {'servers': self.managers_config})

        terraform_template_file.write_text(output)

        self._terraform_inputs_file.write_text(
            json.dumps(
                {
                    'resource_suffix': str(uuid.uuid4()),
                    'public_key_path': self._ssh_key.public_key_path,
                    'private_key_path': self._ssh_key.private_key_path,
                    'flavor': self._get_server_flavor()
                },
                indent=2))

        try:
            with self._tmpdir:
                self._terraform.apply(
                    ['-var-file', self._terraform_inputs_file])
                outputs = util.AttributesDict({
                    k: v['value']
                    for k, v in json.loads(
                        self._terraform.output(['-json']).stdout).items()
                })
            self._attributes.update(outputs)
            self._create_managers_list(outputs)

            if self.preconfigure_callback:
                self.preconfigure_callback(self.managers)

            self._bootstrap_managers()

            for manager in self.managers:
                manager.verify_services_are_running()

            for i, manager in enumerate(self._managers):
                manager.use()
                self._upload_necessary_files_to_manager(
                    manager, openstack_config_file)
                if self.managers_config[i].upload_plugins:
                    self._upload_plugin_to_manager(manager,
                                                   'openstack_centos_core')

            self._logger.info('Cloudify cluster successfully created!')

        except Exception as e:
            self._logger.error(
                'Error creating image based cloudify cluster: %s', e)
            try:
                self.destroy()
            except sh.ErrorReturnCode as ex:
                self._logger.error('Error on terraform destroy: %s', ex)
            raise