def _get_manager_kp(self):
     """
     Retrieves manager kp to the local machine.
     :return: path the local manager kp.
     """
     remote_manager_kp_path = self.env.cloudify_config["ssh_key_filename"]
     local_manager_kp = fab.get(remote_manager_kp_path, self.workdir)[0]
     os.chmod(local_manager_kp, stat.S_IRUSR | stat.S_IWUSR)
     return local_manager_kp
    def _update_example_sg(self):

        example_blueprint_path = os.path.join(
            "{0}-{1}".format(HELLO_WORLD_EXAMPLE_NAME, self.branch), self.get_app_blueprint_file()
        )
        example_blueprint = StringIO()
        fab.get(example_blueprint_path, example_blueprint)
        hello_world_blueprint_yaml = yaml.load(example_blueprint.getvalue())

        hello_world_blueprint_yaml["node_templates"]["security_group"]["properties"]["security_group"] = {
            "description": ""
        }

        example_blueprint.seek(0)
        json.dump(hello_world_blueprint_yaml, example_blueprint)
        example_blueprint.truncate()

        fab.put(example_blueprint, example_blueprint_path)
Exemple #3
0
 def _get_manager_kp(self):
     """
     Retrieves manager kp to the local machine.
     :return: path to the local manager kp.
     """
     remote_manager_kp_path = self.bootstrap_inputs['ssh_key_filename']
     local_manager_kp = fab.get(remote_manager_kp_path, self.workdir)[0]
     os.chmod(local_manager_kp, stat.S_IRUSR | stat.S_IWUSR)
     return local_manager_kp
 def _get_manager_kp(self):
     """
     Retrieves manager kp to the local machine.
     :return: path to the local manager kp.
     """
     remote_manager_kp_path = self.bootstrap_inputs['ssh_key_filename']
     local_manager_kp = fab.get(remote_manager_kp_path, self.workdir)[0]
     os.chmod(local_manager_kp, stat.S_IRUSR | stat.S_IWUSR)
     return local_manager_kp
    def _update_inputs_file(self, additional_inputs):
        """
        Update the remote bootstrap inputs file.

        :param additional_inputs the additional inputs to append
        :return:None
        """
        # Retrieve inputs from cli vm
        inputs_file = StringIO()
        fab.get(self.remote_bootstrap_inputs_path, inputs_file)
        inputs = yaml.load(inputs_file.getvalue())

        # Update the inputs to include the additional inputs
        inputs.update(additional_inputs)
        inputs_file.seek(0)
        json.dump(inputs, inputs_file)
        inputs_file.truncate()

        # Write the inputs back to the cli vm.
        fab.put(inputs_file, self.remote_bootstrap_inputs_path)
 def _get_agent_kp(self):
     """
     Retrieves manager kp to the local machine.
     :return: path to the local manager kp.
     """
     remote_agent_kp_path = \
         self.bootstrap_inputs['agent_private_key_path']
     with fab_env(**self.centos_client_env):
         local_agent_kp = fab.get(remote_agent_kp_path, self.workdir)[0]
     os.chmod(local_agent_kp, stat.S_IRUSR | stat.S_IWUSR)
     return local_agent_kp
Exemple #7
0
 def _get_agent_kp(self):
     """
     Retrieves manager kp to the local machine.
     :return: path to the local manager kp.
     """
     remote_agent_kp_path = \
         self.bootstrap_inputs['agent_private_key_path']
     with fab_env(**self.centos_client_env):
         local_agent_kp = fab.get(remote_agent_kp_path, self.workdir)[0]
     os.chmod(local_agent_kp, stat.S_IRUSR | stat.S_IWUSR)
     return local_agent_kp
Exemple #8
0
    def _update_inputs_file(self, additional_inputs):
        """
        Update the remote bootstrap inputs file.

        :param additional_inputs the additional inputs to append
        :return:None
        """
        # Retrieve inputs from cli vm
        inputs_file = StringIO()
        fab.get(self.remote_bootstrap_inputs_path, inputs_file)
        inputs = yaml.load(inputs_file.getvalue())

        # Update the inputs to include the additional inputs
        inputs.update(additional_inputs)
        inputs_file.seek(0)
        json.dump(inputs, inputs_file)
        inputs_file.truncate()

        # Write the inputs back to the cli vm.
        fab.put(inputs_file, self.remote_bootstrap_inputs_path)
Exemple #9
0
    def _update_example_sg(self):

        example_blueprint_path = \
            os.path.join("{0}-{1}".format(HELLO_WORLD_EXAMPLE_NAME,
                                          self.branch),
                         self.app_blueprint_file)
        example_blueprint = StringIO()
        fab.get(example_blueprint_path, example_blueprint)
        hello_world_blueprint_yaml = yaml.load(example_blueprint.getvalue())

        hello_world_blueprint_yaml['node_templates']['security_group'][
            'properties']['security_group'] = {
                'description': ''
            }

        example_blueprint.seek(0)
        json.dump(hello_world_blueprint_yaml, example_blueprint)
        example_blueprint.truncate()

        fab.put(example_blueprint, example_blueprint_path)
    def _test_cli_package(self):
        """
        Tests cli package in offline mode (Only Linux compatible)
        :return:
        """
        self.keystone_url = self.bootstrap_inputs["keystone_url"]
        iaas_resolver = "{0} {1}".format(*self._resolve_url_to_ip_and_netloc(self.keystone_url))
        iaas_resolver_cmd = "echo {0} >> /etc/hosts".format(iaas_resolver)

        # Make sure cli machine is up with a registered ssh key
        wait_for_vm_to_become_ssh_available(env, self._execute_command, self.logger)

        with self.dns():
            self.logger.info("Preparing CLI and downloading example")
            package_name = self._prepare_cli()
            blueprint_path = self.get_hello_world_blueprint()

        self._assert_offline()
        self._install_cli(package_name)
        self.logger.info("Preparing manager blueprint")
        self.prepare_manager_blueprint()
        self._update_hosts_file(iaas_resolver)

        # Getting the remote manager blueprint and preparing resources
        self.logger.info("Retrieving remote manager blueprint file...")
        manager_blueprint = StringIO()
        fab.get(self.test_manager_blueprint_path, manager_blueprint)
        manager_blueprint_yaml = yaml.load(manager_blueprint.getvalue())
        resources_to_download = self._get_resource_list(manager_blueprint_yaml)

        # each os should implement any vm-related function before this comment

        with FileServer(self._get_file_server_inputs(), resources_to_download, FILE_SERVER_PORT, self.logger) as fs:
            additional_inputs = fs.get_processed_inputs()
            self._update_inputs_file(additional_inputs)

            self.logger.info("Bootstrapping...")
            self.bootstrap_manager()

            # Adding iaas resolver for the manager machine.
            self.logger.info("adding {0} to /etc/hosts of the manager vm".format(iaas_resolver))
            manager_fab_conf = {
                "user": self.client_user,
                "key_filename": self._get_manager_kp(),
                "host_string": self.manager_ip,
                "timeout": 30,
                "connection_attempts": 10,
            }
            wait_for_vm_to_become_ssh_available(manager_fab_conf, self._execute_command, self.logger)
            self._run_cmd_on_custom_machine(iaas_resolver_cmd, manager_fab_conf, sudo=True)

            # Uploading, deploying and testing hello_world blueprint
            # Any sleep is to allow the execution to complete
            # TODO: remove this line when the openstack sg description fix is applied  # NOQA
            self._update_example_sg()

            self.logger.info("Testing the example deployment cycle...")
            blueprint_id = "blueprint-{0}".format(uuid.uuid4())

            self._upload_blueprint(blueprint_path, blueprint_id, self.get_app_blueprint_file())
            self.deployment_id = self.create_deployment(blueprint_id)
            self.addCleanup(self.uninstall_deployment)
            self.install_deployment(self.deployment_id)
            self.assert_deployment_working(self._get_app_property("http_endpoint"))
 def _get_remote_blueprint(self, env=None):
     env = env or self.centos_client_env
     manager_blueprint = StringIO()
     with fab_env(**env):
         fab.get(self.manager_blueprint_path, manager_blueprint)
     return yaml.load(manager_blueprint.getvalue())
Exemple #12
0
 def _get_remote_blueprint(self, env=None):
     env = env or self.centos_client_env
     manager_blueprint = StringIO()
     with fab_env(**env):
         fab.get(self.manager_blueprint_path, manager_blueprint)
     return yaml.load(manager_blueprint.getvalue())
Exemple #13
0
    def _test_cli_package(self):
        """
        Tests cli package in offline mode (Only Linux compatible)
        :return:
        """
        self.keystone_url = self.bootstrap_inputs['keystone_url']
        iaas_resolver = '{0} {1}' \
            .format(*self._resolve_url_to_ip_and_netloc(self.keystone_url))
        iaas_resolver_cmd = 'echo {0} >> /etc/hosts'.format(iaas_resolver)

        # Make sure cli machine is up with a registered ssh key
        wait_for_vm_to_become_ssh_available(env, self._execute_command,
                                            self.logger)

        with self.dns():
            self.logger.info('Preparing CLI and downloading example')
            package_name = self._prepare_cli()
            blueprint_path = self.get_hello_world_blueprint()

        self._install_cli(package_name)
        self.logger.info('Preparing manager blueprint')
        self.prepare_manager_blueprint()
        self._update_hosts_file(iaas_resolver)

        # Getting the remote manager blueprint and preparing resources
        self.logger.info('Retrieving remote manager blueprint file...')
        manager_blueprint = StringIO()
        fab.get(self.test_manager_blueprint_path, manager_blueprint)
        manager_blueprint_yaml = yaml.load(manager_blueprint.getvalue())
        resources_to_download = self._get_resource_list(manager_blueprint_yaml)

        # each os should implement any vm-related function before this comment

        with FileServer(self._get_file_server_inputs(), resources_to_download,
                        FILE_SERVER_PORT, self.logger) as fs:
            additional_inputs = fs.get_processed_inputs()
            self._update_inputs_file(additional_inputs)

            self.logger.info('Bootstrapping...')
            self.bootstrap_manager()

            # Adding iaas resolver for the manager machine.
            self.logger.info(
                'adding {0} to /etc/hosts of the manager vm'.format(
                    iaas_resolver))
            manager_fab_conf = {
                'user': self.client_user,
                'key_filename': self._get_manager_kp(),
                'host_string': self.manager_ip,
                'timeout': 30,
                'connection_attempts': 10
            }
            wait_for_vm_to_become_ssh_available(manager_fab_conf,
                                                self._execute_command,
                                                self.logger)
            self._run_cmd_on_custom_machine(iaas_resolver_cmd,
                                            manager_fab_conf,
                                            sudo=True)

            # Uploading, deploying and testing hello_world blueprint
            # Any sleep is to allow the execution to complete
            # TODO: remove this line when the openstack sg description fix is applied  # NOQA
            self._update_example_sg()

            self.logger.info('Testing the example deployment cycle...')
            blueprint_id = 'blueprint-{0}'.format(uuid.uuid4())

            self._upload_blueprint(blueprint_path, blueprint_id,
                                   self.app_blueprint_file)
            self.deployment_id = self.create_deployment(blueprint_id)
            self.addCleanup(self.uninstall_deployment)
            self.install_deployment(self.deployment_id)
            self.assert_deployment_working(
                self._get_app_property('http_endpoint'))