def test_remote_dir_script_action_method_default(self):
     remote_action = FabricRemoteScriptAction('foo', 'foo-id', '/tmp/st2.py',
                                              None,
                                              on_behalf_user='******',
                                              parallel=True, sudo=False)
     self.assertEqual(remote_action.get_on_behalf_user(), 'stan')
     self.assertEqual(remote_action.remote_dir, '/tmp')
     self.assertEqual(remote_action.remote_script, '/tmp/st2.py')
Пример #2
0
 def test_remote_dir_script_action_method_default(self):
     remote_action = FabricRemoteScriptAction('foo', 'foo-id', '/tmp/st2.py',
                                              None,
                                              on_behalf_user='******',
                                              parallel=True, sudo=False)
     self.assertEqual(remote_action.get_on_behalf_user(), 'stan')
     self.assertEqual(remote_action.remote_dir, '/tmp')
     self.assertEqual(remote_action.remote_script, '/tmp/st2.py')
Пример #3
0
 def test_fabric_remote_script_action_method(self):
     remote_action = FabricRemoteScriptAction('foo', 'foo-id', '/tmp/st2.py',
                                              None,
                                              on_behalf_user='******',
                                              parallel=True, sudo=False)
     self.assertEqual(remote_action.get_on_behalf_user(), 'stan')
     fabric_task = remote_action.get_fabric_task()
     self.assertTrue(fabric_task is not None)
     self.assertTrue(fabric_task.wrapped == remote_action._run_script)
Пример #4
0
    def _get_remote_action(self, action_parameters):
        # remote script actions without entry_point don't make sense, user probably wanted to use
        # "run-remote" action
        if not self.entry_point:
            msg = (
                'Action "%s" is missing entry_point attribute. Perhaps wanted to use '
                '"run-remote" runner?')
            raise Exception(msg % (self.action_name))

        script_local_path_abs = self.entry_point
        pos_args, named_args = self._get_script_args(action_parameters)
        named_args = self._transform_named_args(named_args)
        env_vars = self._get_env_vars()
        remote_dir = self.runner_parameters.get(RUNNER_REMOTE_DIR,
                                                cfg.CONF.ssh_runner.remote_dir)
        remote_dir = os.path.join(remote_dir, self.liveaction_id)
        return FabricRemoteScriptAction(self.action_name,
                                        str(self.liveaction_id),
                                        script_local_path_abs,
                                        self.libs_dir_path,
                                        named_args=named_args,
                                        positional_args=pos_args,
                                        env_vars=env_vars,
                                        on_behalf_user=self._on_behalf_user,
                                        user=self._username,
                                        password=self._password,
                                        private_key=self._private_key,
                                        remote_dir=remote_dir,
                                        hosts=self._hosts,
                                        parallel=self._parallel,
                                        sudo=self._sudo,
                                        timeout=self._timeout,
                                        cwd=self._cwd)
Пример #5
0
    def test_settings_are_used(self, mock_settings, mock_shell_env, mock_put, mock_run):
        # Test that the remote script action uses fabric environment and authentication settings
        named_args = {}
        action = FabricRemoteScriptAction(name='foo', action_exec_id='dummy',
                                          script_local_path_abs='test.py',
                                          script_local_libs_path_abs='/',
                                          remote_dir='/tmp',
                                          named_args=named_args, positional_args=None)

        task = action.get_fabric_task()

        self.assertEqual(mock_settings.call_count, 0)
        self.assertEqual(mock_shell_env.call_count, 0)
        task.run()
        self.assertEqual(mock_settings.call_count, 1)
        self.assertEqual(mock_shell_env.call_count, 1)
Пример #6
0
 def test_remote_dir_script_action_method_override(self):
     remote_action = FabricRemoteScriptAction('foo', 'foo-id', '/tmp/st2.py',
                                              None,
                                              on_behalf_user='******',
                                              parallel=True, sudo=False, remote_dir='/foo')
     self.assertEqual(remote_action.remote_dir, '/foo')
     self.assertEqual(remote_action.remote_script, '/foo/st2.py')
Пример #7
0
 def _get_fabric_remote_script_action(self, action_parameters):
     script_local_path_abs = self.entry_point
     pos_args, named_args = self._get_script_args(action_parameters)
     named_args = self._transform_named_args(named_args)
     env_vars = self._get_env_vars()
     remote_dir = self.runner_parameters.get(RUNNER_REMOTE_DIR,
                                             cfg.CONF.ssh_runner.remote_dir)
     remote_dir = os.path.join(remote_dir, self.liveaction_id)
     return FabricRemoteScriptAction(self.action_name,
                                     str(self.liveaction_id),
                                     script_local_path_abs,
                                     self.libs_dir_path,
                                     named_args=named_args,
                                     positional_args=pos_args,
                                     env_vars=env_vars,
                                     on_behalf_user=self._on_behalf_user,
                                     user=self._username,
                                     password=self._password,
                                     private_key=self._private_key,
                                     remote_dir=remote_dir,
                                     hosts=self._hosts,
                                     parallel=self._parallel,
                                     sudo=self._sudo,
                                     timeout=self._timeout,
                                     cwd=self._cwd)
    def test_settings_are_used(self, mock_settings, mock_shell_env, mock_put,
                               mock_run):
        # Test that the remote script action uses fabric environment and authentication settings
        named_args = {}
        action = FabricRemoteScriptAction(name='foo',
                                          action_exec_id='dummy',
                                          script_local_path_abs='test.py',
                                          script_local_libs_path_abs='/',
                                          remote_dir='/tmp',
                                          named_args=named_args,
                                          positional_args=None)

        task = action.get_fabric_task()

        self.assertEqual(mock_settings.call_count, 0)
        self.assertEqual(mock_shell_env.call_count, 0)
        task.run()
        self.assertEqual(mock_settings.call_count, 1)
        self.assertEqual(mock_shell_env.call_count, 1)
Пример #9
0
        sudo=True)
    results = runner._run(remote_action)

    print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
    print('!!!!!!!!!!!!!!!!!!!!! RESULTS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
    print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')

    print(results)

    print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
    print('!!!!!!!!!!!!!!!!!!!!! SCRIPT DAWG !!!!!!!!!!!!!!!!!!!!!!!!!!!')
    print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
    script_action = FabricRemoteScriptAction('UNAME',
                                             'action_exec_id' +
                                             str(uuid.uuid4()),
                                             '/tmp/ls-script.sh',
                                             named_args={},
                                             positional_args='/tmp',
                                             on_behalf_user='******',
                                             user='******',
                                             hosts=['54.191.85.86'],
                                             parallel=True,
                                             sudo=False)
    results = runner._run(script_action)

    print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
    print('!!!!!!!!!!!!!!!!!!!!! RESULTS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
    print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')

    print(results)