Exemplo n.º 1
0
    def test_instantiation(self):
        action = RemoteScriptAction(
            name="name",
            action_exec_id="aeid",
            script_local_path_abs="/tmp/sc/ma_script.sh",
            script_local_libs_path_abs="/tmp/sc/libs",
            named_args=None,
            positional_args=None,
            env_vars={"a": 1},
            on_behalf_user="******",
            user="******",
            remote_dir="/home/mauser",
            hosts=["127.0.0.1"],
            parallel=False,
            sudo=True,
            timeout=10,
        )
        self.assertEqual(action.name, "name")
        self.assertEqual(action.action_exec_id, "aeid")
        self.assertEqual(action.script_local_libs_path_abs, "/tmp/sc/libs")
        self.assertEqual(action.env_vars, {"a": 1})
        self.assertEqual(action.on_behalf_user, "onbehalf")
        self.assertEqual(action.user, "user")
        self.assertEqual(action.remote_dir, "/home/mauser")
        self.assertEqual(action.hosts, ["127.0.0.1"])
        self.assertEqual(action.parallel, False)
        self.assertEqual(action.sudo, True)
        self.assertEqual(action.timeout, 10)

        self.assertEqual(action.script_local_dir, "/tmp/sc")
        self.assertEqual(action.script_name, "ma_script.sh")
        self.assertEqual(action.remote_script, "/home/mauser/ma_script.sh")
        self.assertEqual(action.command, "/home/mauser/ma_script.sh")
Exemplo n.º 2
0
    def test_instantiation(self):
        action = RemoteScriptAction(
            name='name',
            action_exec_id='aeid',
            script_local_path_abs='/tmp/sc/ma_script.sh',
            script_local_libs_path_abs='/tmp/sc/libs',
            named_args=None,
            positional_args=None,
            env_vars={'a': 1},
            on_behalf_user='******',
            user='******',
            remote_dir='/home/mauser',
            hosts=['127.0.0.1'],
            parallel=False,
            sudo=True,
            timeout=10)
        self.assertEqual(action.name, 'name')
        self.assertEqual(action.action_exec_id, 'aeid')
        self.assertEqual(action.script_local_libs_path_abs, '/tmp/sc/libs')
        self.assertEqual(action.env_vars, {'a': 1})
        self.assertEqual(action.on_behalf_user, 'onbehalf')
        self.assertEqual(action.user, 'user')
        self.assertEqual(action.remote_dir, '/home/mauser')
        self.assertEqual(action.hosts, ['127.0.0.1'])
        self.assertEqual(action.parallel, False)
        self.assertEqual(action.sudo, True)
        self.assertEqual(action.timeout, 10)

        self.assertEqual(action.script_local_dir, '/tmp/sc')
        self.assertEqual(action.script_name, 'ma_script.sh')
        self.assertEqual(action.remote_script, '/home/mauser/ma_script.sh')
        self.assertEqual(action.command, '/home/mauser/ma_script.sh')
Exemplo n.º 3
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 RemoteScriptAction(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)
Exemplo n.º 4
0
    def test_parameter_formatting(self):
        # Only named args
        named_args = {
            '--foo1': 'bar1',
            '--foo2': 'bar2',
            '--foo3': True,
            '--foo4': False
        }

        action = RemoteScriptAction(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)
        self.assertEqual(action.command,
                         '/tmp/test.py --foo1=bar1 --foo2=bar2 --foo3')
Exemplo n.º 5
0
    def test_parameter_formatting(self):
        # Only named args
        named_args = {
            "--foo1": "bar1",
            "--foo2": "bar2",
            "--foo3": True,
            "--foo4": False,
        }

        action = RemoteScriptAction(
            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,
        )
        self.assertEqual(action.command,
                         "/tmp/test.py --foo1=bar1 --foo2=bar2 --foo3")
 def test_cwd_used_correctly(self):
     remote_action = RemoteScriptAction(
         'foo-script',
         bson.ObjectId(),
         script_local_path_abs='/home/stanley/shiz_storm.py',
         script_local_libs_path_abs=None,
         named_args={},
         positional_args=['blank space'],
         env_vars={},
         on_behalf_user='******',
         user='******',
         private_key='---SOME RSA KEY---',
         remote_dir='/tmp',
         hosts=['localhost'],
         cwd='/test/cwd/')
     paramiko_runner = ParamikoRemoteScriptRunner('runner_1')
     paramiko_runner._parallel_ssh_client = ParallelSSHClient(['localhost'],
                                                              'stanley')
     paramiko_runner._run_script_on_remote_host(remote_action)
     ParallelSSHClient.run.assert_called_with(
         "/tmp/shiz_storm.py 'blank space'", cwd='/test/cwd/', timeout=None)