Beispiel #1
0
    def deploy(self):
        test_artifact = TestArtifact.get_by_uuid(self.testartifact_uuid)
        sut_csar_path = os.path.join(test_artifact.fq_storage_path,
                                     test_artifact.sut_tosca_path)
        ti_csar_path = os.path.join(test_artifact.fq_storage_path,
                                    test_artifact.ti_tosca_path)

        # Deployment of SuT
        with Csar(sut_csar_path, extract_dir=self.sut_storage_path,
                  keep=True) as sut_csar:
            if DropPolicies:
                sut_csar.drop_policies()
            entry_definition = sut_csar.tosca_entry_point

            current_app.logger.\
                info(f'Deploying SuT {str(entry_definition)} with opera in folder {str(self.sut_storage_path)}.')
            subprocess.call(['opera', 'deploy', entry_definition],
                            cwd=self.sut_storage_path)

        # Deployment of TI
        with Csar(ti_csar_path, extract_dir=self.ti_storage_path,
                  keep=True) as ti_csar:
            if DropPolicies:
                ti_csar.drop_policies()
            entry_definition = ti_csar.tosca_entry_point

            if entry_definition:
                current_app.logger.\
                    info(f'Deploying TI {str(entry_definition)} with opera in folder {str(self.ti_storage_path)}.')
                subprocess.call(['opera', 'deploy', entry_definition],
                                cwd=self.ti_storage_path)

        time.sleep(30)

        envFaasScenario = os.getenv('CTT_FAAS_ENABLED')
        faas_mode = False
        if envFaasScenario:
            if envFaasScenario == "1":
                faas_mode = True
        elif FaasScenario:
            faas_mode = True

        if faas_mode:
            # FaaS scenario
            deployed_systems = Deployment.deployment_workaround(
                exclude_sut=True)
            self.sut_hostname = self.__test_artifact.policy_yaml['properties'][
                'hostname']
            self.ti_hostname = deployed_systems['ti']
        else:
            deployed_systems = Deployment.deployment_workaround(
                exclude_sut=False)
            self.sut_hostname = deployed_systems['sut']
            self.ti_hostname = deployed_systems['ti']

        db_session.add(self)
        db_session.commit()
Beispiel #2
0
    def parse_policies(cls, sut_file_path=None):
        if sut_file_path:
            with Csar(sut_file_path) as sut_csar:
                entry_point = sut_csar.tosca_entry_point
                sut_tosca = sut_csar.file_as_dict(entry_point)
                try:
                    return sut_tosca['topology_template']['policies']
                except LookupError as e:
                    current_app.logger.debug(f'Policies could not be found in {sut_file_path}.')

        else:
            return [
                {
                    'SimplePingTest': {
                        'type': 'radon.policies.testing.PingTest',
                        'properties': {
                            'hostname': 'localhost',
                            'ti_blueprint': 'radon.blueprints.DeploymentTestAgent',
                            'test_id': 'pingtest_123',
                        },
                        'targets': ['SockShop'],
                    }
                },
                {
                    'SimpleEndpointTest': {
                        'type': 'radon.policies.testing.HttpEndpointTest',
                        'properties': {
                            'path': "/cart/",
                            'hostname': 'localhost',
                            'method': "GET",
                            'port': 80,
                            'expected_status': 200,
                            'expected_body': None,
                            'ti_blueprint': None,
                            'use_https': False,
                            'test_body': None,
                            'test_header': None,
                            'test_id': None,
                        },
                        'targets': ['SockShop'],
                    }
                },
                {
                    'SimpleJMeterLoadTest': {
                        'type': 'radon.policies.testing.JMeterLoadTest',
                        'properties': {
                            'jmx_file': 'sockshop.jmx',
                            'hostname': 'localhost',
                            'port': 8080,
                            'ti_blueprint': 'radon.blueprints.testing.JMeterMasterOnly',
                            'user.properties': None,
                            'test_id': 'loadtest213',
                        },
                        'targets': ['SockShop'],
                    }
                }
            ]
Beispiel #3
0
    def deploy(self):
        test_artifact = TestArtifact.get_by_uuid(self.testartifact_uuid)
        sut_csar_path = os.path.join(test_artifact.fq_storage_path,
                                     test_artifact.sut_tosca_path)
        ti_csar_path = os.path.join(test_artifact.fq_storage_path,
                                    test_artifact.ti_tosca_path)

        if test_artifact.sut_inputs_path:
            sut_inputs_path = os.path.join(test_artifact.fq_storage_path,
                                           test_artifact.sut_inputs_path)
        else:
            sut_inputs_path = None

        if test_artifact.ti_inputs_path:
            ti_inputs_path = os.path.join(test_artifact.fq_storage_path,
                                          test_artifact.ti_inputs_path)
        else:
            ti_inputs_path = None

        # Deployment of SuT
        with Csar(sut_csar_path, extract_dir=self.sut_storage_path,
                  keep=True) as sut_csar:
            if DropPolicies:
                sut_csar.drop_policies()
            entry_definition = sut_csar.tosca_entry_point

            current_app.logger.\
                info(f'Deploying SuT {str(entry_definition)} with opera in folder {str(self.sut_storage_path)}.')
            try:
                if sut_inputs_path:
                    subprocess.call([
                        'opera', 'deploy', '-p', self.sut_storage_path, '-i',
                        sut_inputs_path, entry_definition
                    ],
                                    cwd=self.sut_storage_path)
                else:
                    subprocess.call([
                        'opera', 'deploy', '-p', self.sut_storage_path,
                        entry_definition
                    ],
                                    cwd=self.sut_storage_path)
                opera_outputs = subprocess.check_output(
                    ['opera', 'outputs', '-p', self.sut_storage_path],
                    cwd=self.sut_storage_path)
                current_app.logger.info(
                    f'Opera returned output {opera_outputs}.')
            except OperationError:
                subprocess.call(
                    ['opera', 'undeploy', '-p', self.sut_storage_path])

        # Deployment of TI
        with Csar(ti_csar_path, extract_dir=self.ti_storage_path,
                  keep=True) as ti_csar:
            if DropPolicies:
                ti_csar.drop_policies()
            entry_definition = ti_csar.tosca_entry_point

            if entry_definition:
                current_app.logger.\
                    info(f'Deploying TI {str(entry_definition)} with opera in folder {str(self.ti_storage_path)}.')

                try:
                    if ti_inputs_path:
                        subprocess.call([
                            'opera', 'deploy', '-p', self.ti_storage_path,
                            '-i', ti_inputs_path, entry_definition
                        ],
                                        cwd=self.ti_storage_path)
                    else:
                        subprocess.call([
                            'opera', 'deploy', '-p', self.ti_storage_path,
                            entry_definition
                        ],
                                        cwd=self.ti_storage_path)
                    opera_outputs = subprocess.check_output(
                        ['opera', 'outputs', '-p', self.ti_storage_path],
                        cwd=self.ti_storage_path)
                    current_app.logger.info(
                        f'Opera returned output {opera_outputs}.')
                    opera_yaml_outputs = yaml.safe_load(opera_outputs)
                except OperationError:
                    subprocess.call(
                        ['opera', 'undeploy', '-p', self.ti_storage_path])

        time.sleep(30)

        # FaaS scenario
        # deployed_systems = Deployment.deployment_workaround(exclude_sut=True)
        self.sut_hostname = self.__test_artifact.policy_yaml['properties'][
            'hostname']
        current_app.logger.info(f'SUT hostname {self.sut_hostname}.')
        self.ti_hostname = opera_yaml_outputs['public_address']['value']
        current_app.logger.info(f'TI hostname {self.ti_hostname}.')
        # self.ti_hostname = deployed_systems['ti']

        db_session.add(self)
        db_session.commit()
Beispiel #4
0
    def deploy(self):
        test_artifact = TestArtifact.get_by_uuid(self.testartifact_uuid)
        sut_csar_path = os.path.join(test_artifact.fq_storage_path, test_artifact.sut_tosca_path)
        ti_csar_path = os.path.join(test_artifact.fq_storage_path, test_artifact.ti_tosca_path)
        sut_success: bool = False

        if test_artifact.sut_inputs_path:
            sut_inputs_path = os.path.join(test_artifact.fq_storage_path, test_artifact.sut_inputs_path)
        else:
            sut_inputs_path = None

        if test_artifact.ti_inputs_path:
            ti_inputs_path = os.path.join(test_artifact.fq_storage_path, test_artifact.ti_inputs_path)
        else:
            ti_inputs_path = None

        # Deployment of SuT
        with Csar(sut_csar_path, extract_dir=self.sut_storage_path, keep=True) as sut_csar:
            if DropPolicies:
                sut_csar.drop_policies()
            entry_definition = sut_csar.tosca_entry_point

            if not is_test_mode():
                current_app.logger. \
                    info(f'Deploying SuT {str(entry_definition)} with opera in folder {str(self.sut_storage_path)}.')

                return_code: int
                try:
                    if sut_inputs_path:
                        return_code = subprocess.call(['opera', 'deploy',
                                                       '-p', self.sut_storage_path,
                                                       '-i', sut_inputs_path,
                                                       entry_definition],
                                                      cwd=self.sut_storage_path)
                    else:
                        return_code = subprocess.call(['opera', 'deploy',
                                                       '-p', self.sut_storage_path,
                                                       entry_definition],
                                                      cwd=self.sut_storage_path)

                    if return_code == 0:
                        sut_success = True
                        opera_outputs = subprocess.check_output(['opera', 'outputs',
                                                                 '-p', self.sut_storage_path],
                                                                cwd=self.sut_storage_path)
                        current_app.logger.info(f'Opera returned output {opera_outputs}.')
                        opera_yaml_outputs_sut = yaml.safe_load(opera_outputs)
                    else:
                        error_message: str = f'Deployment of SUT failed with Opera return code ${return_code}.'
                        current_app.logger.info(error_message)
                        raise OperationError(error_message)
                except OperationError:
                    subprocess.call(['opera', 'undeploy',
                                     '-p', self.sut_storage_path])
            else:
                current_app.logger.info(f'Deployment of SUT skipped due to test mode being enabled.')
                sut_success = True

        # Deployment of TI
        with Csar(ti_csar_path, extract_dir=self.ti_storage_path, keep=True) as ti_csar:
            if DropPolicies:
                ti_csar.drop_policies()
            entry_definition = ti_csar.tosca_entry_point

            if entry_definition:
                current_app.logger. \
                    info(f'Deploying TI {str(entry_definition)} with opera in folder {str(self.ti_storage_path)}.')

                if sut_success and (not is_test_mode()):
                    return_code: int

                    try:
                        if ti_inputs_path:
                            return_code = subprocess.call(['opera', 'deploy',
                                                           '-p', self.ti_storage_path,
                                                           '-i', ti_inputs_path,
                                                           entry_definition],
                                                          cwd=self.ti_storage_path)
                        else:
                            return_code = subprocess.call(['opera', 'deploy',
                                                           '-p', self.ti_storage_path,
                                                           entry_definition],
                                                          cwd=self.ti_storage_path)

                        if return_code == 0:
                            opera_outputs = subprocess.check_output(['opera', 'outputs',
                                                                     '-p', self.ti_storage_path],
                                                                    cwd=self.ti_storage_path)
                            current_app.logger.info(f'Opera returned output {opera_outputs}.')
                            opera_yaml_outputs_ti = yaml.safe_load(opera_outputs)
                            time.sleep(30)
                        else:
                            error_message: str = f'Deployment of TI failed with Opera return code ${return_code}.'
                            current_app.logger.info(error_message)
                            raise OperationError(error_message)
                    except OperationError:
                        subprocess.call(['opera', 'undeploy',
                                         '-p', self.ti_storage_path])

                    # Set SUT hostname to the value of the opera output of the SUT
                    # with the name from the policy field for hostname
                    policy_hostname: str = self.__test_artifact.policy_yaml['properties']['hostname']
                    if policy_hostname in opera_yaml_outputs_sut and 'value' in opera_yaml_outputs_sut[policy_hostname]:
                        self.sut_hostname = opera_yaml_outputs_sut[policy_hostname]['value']
                    else:
                        # Set hostname to field set in the policy field for hostname
                        self.sut_hostname = policy_hostname
                    current_app.logger.info(f'SUT hostname {self.sut_hostname}.')

                    # Set TI hostname to the 'public_address' value of the opera output
                    self.ti_hostname = opera_yaml_outputs_ti['public_address']['value']
                    current_app.logger.info(f'TI hostname {self.ti_hostname}.')

                elif not sut_success:
                    current_app.logger.warning(f'Deployment of TI skipped due to failure of SUT deployment.')
                elif is_test_mode():
                    current_app.logger.info(f'Deployment of TI skipped due to test mode being enabled.')

        db_session.add(self)
        db_session.commit()