示例#1
0
    def _undeploy(location: Path, inv: ExtendedInvocation):

        # get blueprint
        CSAR_db.get_revision(inv.blueprint_id, location, inv.version_id)
        # get session data (.opera)
        if not InvocationService.get_dot_opera_from_db(inv.deployment_id,
                                                       location):
            raise MissingDeploymentDataError(
                'Could not get .opera data from previous job, aborting...')

        with xopera_util.cwd(location):
            try:
                if inv.user_id and Settings.secure_workdir:
                    xopera_util.setup_user([location], inv.user_id,
                                           inv.access_token)
                opera_storage = Storage.create(".opera")
                if inv.inputs:
                    opera_storage.write_json(inv.inputs, "inputs")
                opera_undeploy(opera_storage,
                               verbose_mode=False,
                               num_workers=inv.workers)
                # Outputs in undeployment are not returned
                return None
            finally:
                if inv.user_id and Settings.secure_workdir:
                    xopera_util.cleanup_user()
示例#2
0
    def _deploy_continue(location: Path, inv: ExtendedInvocation):

        # get blueprint
        CSAR_db.get_revision(inv.blueprint_id, location, inv.version_id)
        # get session data (.opera)
        InvocationService.get_dot_opera_from_db(inv.deployment_id, location)

        with xopera_util.cwd(location):
            try:
                if inv.user_id and Settings.secure_workdir:
                    xopera_util.setup_user([location], inv.user_id,
                                           inv.access_token)
                opera_storage = Storage.create(".opera")
                service_template = entry_definitions(location)
                opera_deploy(service_template,
                             inv.inputs,
                             opera_storage,
                             verbose_mode=False,
                             num_workers=inv.workers,
                             delete_existing_state=inv.clean_state)
                outputs = opera_outputs(opera_storage)
                return outputs
            finally:
                if inv.user_id and Settings.secure_workdir:
                    xopera_util.cleanup_user()
示例#3
0
    def test_setup_user(self, mocker, tmp_path_factory):
        location = tmp_path_factory.mktemp("temp")
        file = location / "hello.txt"
        file.write_text("hello")
        os.chmod(location, 0o755)
        os.chmod(file, 0o755)
        mock = mocker.MagicMock()
        mock.pw_uid = os.getuid()
        mock.pw_gid = os.getgid()
        mock.pw_dir = str(location)
        user_mock = mocker.patch("pwd.getpwnam", return_value=mock)

        mocker.patch("os.setgid")
        mocker.patch("os.setuid")
        xopera_util.setup_user([Path(location)], "test", None)

        permissions = oct(os.stat(file).st_mode & stat.S_IRWXU)

        assert permissions == '0o700'
        user_mock.assert_called_with("test")
示例#4
0
    def _update(location: Path, inv: ExtendedInvocation):

        storage_old, location_old, storage_new, location_new = InvocationWorkerProcess.prepare_two_workdirs(
            inv.deployment_id, inv.blueprint_id, inv.version_id, inv.inputs,
            location)

        assert location_new == str(location)

        with xopera_util.cwd(location_new):
            try:
                if inv.user_id and Settings.secure_workdir:
                    xopera_util.setup_user([location_old, location_new],
                                           inv.user_id, inv.access_token)
                instance_diff = opera_diff_instances(storage_old,
                                                     location_old,
                                                     storage_new,
                                                     location_new,
                                                     opera_TemplateComparer(),
                                                     opera_InstanceComparer(),
                                                     verbose_mode=False)

                opera_update(storage_old,
                             location_old,
                             storage_new,
                             location_new,
                             opera_InstanceComparer(),
                             instance_diff,
                             verbose_mode=False,
                             num_workers=inv.workers,
                             overwrite=False)
                outputs = opera_outputs(storage_new)
                return outputs
            finally:
                if inv.user_id and Settings.secure_workdir:
                    xopera_util.cleanup_user()
                shutil.rmtree(location_old)