def test_run_with_save(self):
        _ctx = self._gen_ctx()
        connection_mock = MagicMock()
        connection_mock.connect = MagicMock(return_value="")
        connection_mock.run = MagicMock(return_value="localhost")

        with patch("cloudify_terminal.terminal_connection.connection",
                   MagicMock(return_value=connection_mock)):
            tasks.run(calls=[{
                'action': 'hostname\n \nls',
                'save_to': 'place_for_save'
            }],
                      terminal_auth={
                          'ip': 'ip',
                          'user': '******',
                          'password': '******',
                          'store_logs': True
                      })

        connection_mock.run.assert_has_calls(
            [call('hostname', None, None, []),
             call('ls', None, None, [])])

        self.assertEqual(
            _ctx.instance.runtime_properties.get('place_for_save'),
            'localhost\nlocalhost')
 def test_run_auth_several_ips(self):
     self._gen_ctx()
     ssh_mock = MagicMock()
     ssh_mock.connect = MagicMock(side_effect=OSError("e"))
     with patch("paramiko.SSHClient", MagicMock(return_value=ssh_mock)):
         with self.assertRaises(OperationRetry):
             tasks.run(calls=[{
                 'action': 'ls'
             }],
                       terminal_auth={
                           'ip': ['ip1', 'ip2'],
                           'user': '******',
                           'password': '******'
                       })
     ssh_mock.connect.assert_has_calls([
         call('ip1',
              allow_agent=False,
              look_for_keys=False,
              password='******',
              port=22,
              timeout=5,
              username='******'),
         call('ip2',
              allow_agent=False,
              look_for_keys=False,
              password='******',
              port=22,
              timeout=5,
              username='******')
     ])
 def test_run_auth_enabled_logs(self):
     _ctx = self._gen_ctx()
     connection_mock = MagicMock()
     connection_mock.connect = MagicMock(side_effect=OSError("e"))
     with patch("cloudify_terminal.terminal_connection.connection",
                MagicMock(return_value=connection_mock)):
         with self.assertRaises(OperationRetry):
             tasks.run(calls=[{
                 'action': 'ls'
             }],
                       terminal_auth={
                           'ip': 'ip',
                           'user': '******',
                           'password': '******',
                           'store_logs': True
                       })
     connection_mock.connect.assert_called_with(
         'ip',
         'user',
         'password',
         None,
         22,
         None,
         log_file_name='/tmp/terminal-execution_id_node_name_None.log',
         logger=_ctx.logger)
    def test_run_run_with_text_template(self):
        _ctx = self._gen_ctx()
        connection_mock = MagicMock()
        connection_mock.connect = MagicMock(return_value="")
        connection_mock.run = MagicMock(return_value="localhost")

        with patch("cloudify_terminal.terminal_connection.connection",
                   MagicMock(return_value=connection_mock)):
            tasks.run(calls=[{
                'template_text': ""
            }, {
                'template_text': "bb"
            }, {
                'template_text': "{{ aa }}",
                'params': {
                    'aa': 'gg'
                }
            }],
                      terminal_auth={
                          'ip': 'ip',
                          'user': '******',
                          'password': '******'
                      })

        connection_mock.run.assert_has_calls(
            [call('bb', None, None, []),
             call('gg', None, None, [])])

        self.assertIsNone(
            _ctx.instance.runtime_properties.get('place_for_save'))
Ejemplo n.º 5
0
    def test_run_run_with_close(self):
        _ctx = self._gen_ctx()
        connection_mock = Mock()
        connection_mock.connect = Mock(return_value="")
        connection_mock.run = Mock(return_value="localhost")
        connection_mock.is_closed = Mock(side_effect=[False, True])

        with patch("cloudify_terminal.terminal_connection.RawConnection",
                   Mock(return_value=connection_mock)):
            tasks.run(calls=[{}],
                      terminal_auth={
                          'ip': 'ip',
                          'user': '******',
                          'password': '******',
                          'store_logs': True
                      })

        connection_mock.run.assert_has_calls([
            call(command='exit',
                 prompt_check=None,
                 warning_examples=[],
                 error_examples=[],
                 critical_examples=[])
        ])

        self.assertIsNone(
            _ctx.instance.runtime_properties.get('place_for_save'))
Ejemplo n.º 6
0
    def test_run_run_without_save(self):
        _ctx = self._gen_ctx()
        connection_mock = Mock()
        connection_mock.connect = Mock(return_value="")
        connection_mock.run = Mock(return_value="localhost")

        with patch("cloudify_terminal.terminal_connection.RawConnection",
                   Mock(return_value=connection_mock)):
            tasks.run(calls=[{
                'action': 'hostname'
            }],
                      terminal_auth={
                          'ip': 'ip',
                          'user': '******',
                          'password': '******',
                          'store_logs': True
                      })

        connection_mock.run.assert_called_with(command='hostname',
                                               prompt_check=None,
                                               warning_examples=[],
                                               error_examples=[],
                                               critical_examples=[],
                                               responses=[])

        self.assertIsNone(
            _ctx.instance.runtime_properties.get('place_for_save'))
Ejemplo n.º 7
0
    def test_run_without_any_real_calls(self):
        self._gen_ctx()
        connection_mock = Mock()
        connection_mock.connect = Mock(return_value="")
        connection_mock.run = Mock(return_value="")

        with patch("cloudify_terminal.terminal_connection.connection",
                   Mock(return_value=connection_mock)):
            tasks.run(
                calls=[{}],
                terminal_auth={'ip': 'ip', 'user': '******',
                               'password': '******', 'store_logs': True}
            )

        connection_mock.run.assert_not_called()
Ejemplo n.º 8
0
 def test_run_auth_with_host_ip(self):
     _ctx = self._gen_ctx()
     ssh_mock = Mock()
     ssh_mock.connect = Mock(side_effect=OSError("e"))
     with patch("paramiko.SSHClient", Mock(return_value=ssh_mock)):
         with self.assertRaises(OperationRetry):
             _ctx.instance.host_ip = 'ip'
             tasks.run(
                 calls=[{'action': 'ls'}],
                 terminal_auth={'user': '******',
                                'password': '******'}
             )
     ssh_mock.connect.assert_called_with(
         'ip', allow_agent=False, look_for_keys=False, password='******',
         port=22, timeout=5, username='******')
Ejemplo n.º 9
0
    def test_run_run_without_save(self):
        _ctx = self._gen_ctx()
        connection_mock = Mock()
        connection_mock.connect = Mock(return_value="")
        connection_mock.run = Mock(return_value="localhost")

        with patch("cloudify_terminal.terminal_connection.connection",
                   Mock(return_value=connection_mock)):
            tasks.run(
                calls=[{'action': 'hostname'}],
                terminal_auth={'ip': 'ip', 'user': '******',
                               'password': '******', 'store_logs': True}
            )

        connection_mock.run.assert_called_with('hostname', None, None, [])

        self.assertIsNone(
            _ctx.instance.runtime_properties.get('place_for_save'))
Ejemplo n.º 10
0
 def test_run_auth_enabled_logs(self):
     self._gen_ctx()
     connection_mock = Mock()
     connection_mock.connect = Mock(side_effect=OSError("e"))
     with patch("cloudify_terminal.terminal_connection.RawConnection",
                Mock(return_value=connection_mock)):
         with self.assertRaises(OperationRetry):
             tasks.run(calls=[{
                 'action': 'ls'
             }],
                       terminal_auth={
                           'ip': 'ip',
                           'user': '******',
                           'password': '******',
                           'store_logs': True
                       })
     connection_mock.connect.assert_called_with('ip', 'user', 'password',
                                                None, 22, None)
Ejemplo n.º 11
0
    def test_run_run_with_template(self):
        _ctx = self._gen_ctx()
        connection_mock = Mock()
        connection_mock.connect = Mock(return_value="")
        connection_mock.run = Mock(return_value="localhost")
        _ctx.get_resource = Mock(side_effect=[False, "bb", "{{ aa }}"])

        with patch("cloudify_terminal.terminal_connection.RawConnection",
                   Mock(return_value=connection_mock)):
            tasks.run(calls=[{
                'template': '1.txt'
            }, {
                'template': '2.txt'
            }, {
                'template': '3.txt',
                'params': {
                    'aa': 'gg'
                }
            }],
                      terminal_auth={
                          'ip': 'ip',
                          'user': '******',
                          'password': '******'
                      })

        connection_mock.run.assert_has_calls([
            call(command='bb',
                 prompt_check=None,
                 warning_examples=[],
                 error_examples=[],
                 critical_examples=[],
                 responses=[]),
            call(command='gg',
                 prompt_check=None,
                 warning_examples=[],
                 error_examples=[],
                 critical_examples=[],
                 responses=[])
        ])

        self.assertIsNone(
            _ctx.instance.runtime_properties.get('place_for_save'))
 def test_run_auth(self):
     self._gen_ctx()
     ssh_mock = MagicMock()
     ssh_mock.connect = MagicMock(side_effect=OSError("e"))
     with patch("paramiko.SSHClient", MagicMock(return_value=ssh_mock)):
         with self.assertRaises(NonRecoverableError):
             tasks.run(calls=[{
                 'action': 'ls'
             }],
                       terminal_auth={
                           'ip': 'ip',
                           'user': '******',
                           'password': '******'
                       })
     ssh_mock.connect.assert_called_with('ip',
                                         allow_agent=False,
                                         look_for_keys=False,
                                         password='******',
                                         port=22,
                                         timeout=5,
                                         username='******')
Ejemplo n.º 13
0
    def test_run_with_save_responses(self):
        _ctx = self._gen_ctx()
        connection_mock = Mock()
        connection_mock.connect = Mock(return_value="")
        connection_mock.run = Mock(return_value="localhost")

        with patch("cloudify_terminal.terminal_connection.RawConnection",
                   Mock(return_value=connection_mock)):
            tasks.run(calls=[{
                'action':
                'hostname',
                'save_to':
                'place_for_save',
                'responses': [{
                    'question': 'yes?',
                    'answer': 'no'
                }],
                'errors': ['error'],
                'promt_check': ['#']
            }],
                      terminal_auth={
                          'ip': 'ip',
                          'user': '******',
                          'password': '******',
                          'store_logs': True
                      })

        connection_mock.run.assert_called_with(command='hostname',
                                               prompt_check=['#'],
                                               warning_examples=[],
                                               error_examples=['error'],
                                               critical_examples=[],
                                               responses=[{
                                                   'question': 'yes?',
                                                   'answer': 'no'
                                               }])

        self.assertEqual(
            _ctx.instance.runtime_properties.get('place_for_save'),
            'localhost')
 def test_run_without_auth(self):
     self._gen_ctx()
     with self.assertRaises(NonRecoverableError):
         tasks.run(calls=[{'action': 'ls'}])
 def test_run_without_calls(self):
     self._gen_ctx()
     tasks.run()