def execute(self, results):
        """
        Executes the action_block in the PinFile
        """

        for action in self.action_data["actions"]:
            result = {}

            res_str = json.dumps(results, separators=(',', ':'))
            context = self.action_data.get("context", True)
            path = self.action_data["path"]
            file_path = "{0}/{1}".format(path, action)

            command = self.add_ctx_params(file_path, context)
            run_data = run_rb(command, arguments=res_str)

            print(run_data.stdout)

            data = run_data.stderr
            try:
                if data:
                    result['data'] = json.loads(data)
            except ValueError:
                print("Warning: '{0}' is not a valid JSON object.  "
                      "Data from this hook will be discarded".format(data))

            result['return_code'] = run_data.exitcode
            result['state'] = str(self.state)
            results.append(result)

        return results
    def execute(self):
        """
        Executes the action_block in the PinFile
        """

        for action in self.action_data["actions"]:
            context = self.action_data.get("context", True)
            path = self.action_data["path"]
            file_path = "{0}/{1}".format(path, action)

            command = self.add_ctx_params(file_path, context)
            success = run_rb(command)
            return success
    def execute(self):

        """
        Executes the action_block in the PinFile
        """

        for action in self.action_data["actions"]:
            context = self.action_data.get("context", True)
            path = self.action_data["path"]
            file_path = "{0}/{1}".format(
                        path,
                        action
            )

            command = self.add_ctx_params(file_path, context)
            success = run_rb(command)
            return success
示例#4
0
    def execute(self, results):
        """
        Executes the action_block in the PinFile
        """

        tmpdir = tempfile.mkdtemp()
        for action in self.action_data["actions"]:
            result = {}

            data_path = os.path.join(tmpdir, action)
            res_str = json.dumps(results, separators=(',', ':'))
            context = self.action_data.get("context", True)
            path = self.action_data["path"]
            hook_path = "{0}/{1}".format(path, action)

            command = self.add_ctx_params(hook_path, res_str, data_path,
                                          context)
            run_data = run_rb(command, arguments=res_str)

            try:
                data_file = open(data_path, 'r')
                data = data_file.read()
                if data:
                    result['data'] = json.loads(data)
                data_file.close()
            except IOError:
                # if an IOError is thrown, the file does not exist
                result['data'] = ''
            except ValueError:
                print("Warning: '{0}' is not a valid JSON object.  "
                      "Data from this hook will be discarded".format(data))

            if not run_data:
                result['return_code'] = 1
            else:
                result['return_code'] = 0
            result['state'] = str(self.state)
            results.append(result)

        shutil.rmtree(tmpdir)
        return results
示例#5
0
 def test_run_rb_fail_suppress_exitstatus_false(self):
     with self.assertRaises(SystemExit):
         out = run_rb(
             self.ruby_fail_path, suppress_exit_status_call=False
         )  # when suppress_exit_status=True, Python script stopped prematurely
示例#6
0
 def test_run_rb_fail_suppress_stderr(self):
     out = run_rb(self.ruby_fail_path, suppress_stderr=True)
     self.assertEqual(False, out)  # returns False
示例#7
0
 def test_run_rb_success_suppress_stdout(self):
     out = run_rb(self.ruby_success_path, suppress_stdout=True)
     self.assertEqual(
         b'success\n',
         out)  # still returns a value, does not print to std out
示例#8
0
 def test_run_rb_success(self):
     out = run_rb(self.ruby_success_path)
     self.assertEqual(b'success\n', out)
示例#9
0
 def test_run_rb_fail_suppress_exitstatus_false(self):
     with self.assertRaises(SystemExit):
         out = run_rb(self.ruby_fail_path, suppress_exit_status_call=False) # when suppress_exit_status=True, Python script stopped prematurely
示例#10
0
 def test_run_rb_fail_suppress_stderr(self):
     out = run_rb(self.ruby_fail_path, suppress_stderr=True)
     self.assertEqual(False, out)  # returns False
示例#11
0
 def test_run_rb_success_suppress_stdout(self):
     out = run_rb(self.ruby_success_path, suppress_stdout=True)
     self.assertEqual(b'success\n', out) # still returns a value, does not print to std out
示例#12
0
 def test_run_rb_success(self):
     out = run_rb(self.ruby_success_path)
     self.assertEqual(b'success\n', out)