def test_refuse_ssh_nonexistent_cluster(self):
     response = mock_response(status_code=404)
     with patch('requests.get', MagicMock(return_value=response)), \
             mock_home():
         self.assertRaisesRegexp(
             ExitWithError, 'cluster1 does not exist',
             ssh_cluster, 'cluster1', self.config)
 def test_refuse_ssh_cluster_for_error_statuses(self):
     response = mock_response(status_code=500)
     with patch('requests.get', MagicMock(return_value=response)), \
             mock_home():
         self.assertRaisesRegexp(
             ResponseError, 'Cannot get cluster details',
             ssh_cluster, 'cluster1', self.config)
Exemplo n.º 3
0
 def test_refuse_ssh_cluster_for_error_statuses(self):
     response = mock_response(status_code=500)
     with patch('requests.get', MagicMock(return_value=response)), \
             mock_home():
         self.assertRaisesRegexp(ResponseError,
                                 'Cannot get cluster details', ssh_cluster,
                                 'cluster1', self.config)
Exemplo n.º 4
0
 def test_refuse_ssh_clusters_in_post_running_states(self):
     for state in ['terminating', 'terminated', 'failed']:
         response = mock_response(json=dict(state=state))
         with patch('requests.get', MagicMock(return_value=response)), \
                 mock_home():
             self.assertRaisesRegexp(ExitWithError,
                                     'cluster in %s state' % state,
                                     ssh_cluster, 'cluster1', self.config)
 def test_refuse_ssh_clusters_in_post_running_states(self):
     for state in ['terminating', 'terminated', 'failed']:
         response = mock_response(json=dict(state=state))
         with patch('requests.get', MagicMock(return_value=response)), \
                 mock_home():
             self.assertRaisesRegexp(
                 ExitWithError, 'cluster in %s state' % state,
                 ssh_cluster, 'cluster1', self.config)
 def test_exit_with_error_when_ssh_command_is_not_executable(self):
     response = mock_response(json=MagicMock(side_effect=[RUNNING, PROFILE]))
     call_mock = MagicMock(side_effect=OSError())
     with patch('requests.get', MagicMock(return_value=response)), \
             patch('subprocess.call', call_mock), mock_home():
         self.assertRaisesRegexp(ExitWithError, 'Cannot execute',
                                 ssh_cluster, 'cluster1', self.config)
     self.assertEmptyIterator(response.json.side_effect)
Exemplo n.º 7
0
 def test_exit_with_error_when_ssh_command_is_not_executable(self):
     response = mock_response(json=MagicMock(
         side_effect=[RUNNING, PROFILE]))
     call_mock = MagicMock(side_effect=OSError())
     with patch('requests.get', MagicMock(return_value=response)), \
             patch('subprocess.call', call_mock), mock_home():
         self.assertRaisesRegexp(ExitWithError, 'Cannot execute',
                                 ssh_cluster, 'cluster1', self.config)
     self.assertEmptyIterator(response.json.side_effect)
 def test_poll_service_until_provisioned(self):
     response = mock_response(json=MagicMock(side_effect=[
         PROVISIONING, PROVISIONING, PROVISIONING, RUNNING, PROFILE]))
     call_mock = MagicMock(return_value=0)
     with mock_home() as home, collect_outputs(), \
             patch('requests.get', MagicMock(return_value=response)), \
             patch('subprocess.call', call_mock), patch('time.sleep'):
         self.assertEquals(0, ssh_cluster('cluster1', self.config))
         self.assertEquals(home.read_last_cluster(), "cluster1")
     self.assertEmptyIterator(response.json.side_effect)
Exemplo n.º 9
0
 def test_poll_service_until_provisioned(self):
     response = mock_response(json=MagicMock(side_effect=[
         PROVISIONING, PROVISIONING, PROVISIONING, RUNNING, PROFILE
     ]))
     call_mock = MagicMock(return_value=0)
     with mock_home() as home, collect_outputs(), \
             patch('requests.get', MagicMock(return_value=response)), \
             patch('subprocess.call', call_mock), patch('time.sleep'):
         self.assertEquals(0, ssh_cluster('cluster1', self.config))
         self.assertEquals(home.read_last_cluster(), "cluster1")
     self.assertEmptyIterator(response.json.side_effect)
Exemplo n.º 10
0
 def test_with_config(self):
     sample_conf = {
         "api_key": "AAAA",
         "api_secret": "BBBB",
         "api_url": "http://localhost/cosmos/v1",
         "ssh": "ssh"
     }
     with mock_home(config=sample_conf):
         def command(args, name, config):
             return "%s-%s" % (name, config.api_key)
         decorated = config.with_config(command)
         self.assertEquals(decorated(self.args, "command1"), "command1-AAAA")
Exemplo n.º 11
0
 def test_ssh_clusters_in_running_state(self):
     response = mock_response(json=MagicMock(
         side_effect=[RUNNING, PROFILE]))
     call_mock = MagicMock(return_value=0)
     with patch('requests.get', MagicMock(return_value=response)), \
             patch('subprocess.call', call_mock), mock_home():
         self.assertEquals(0, ssh_cluster('cluster1', self.config))
     call_mock.assert_called_with([
         'ssh', '192.168.20.18', '-l', 'user1', '-o',
         'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no',
         '-L1:192.168.20.18:1', '-L2:192.168.20.18:2', '-L3:192.168.20.18:3'
     ])
     self.assertEmptyIterator(response.json.side_effect)
Exemplo n.º 12
0
 def test_ssh_clusters_in_running_state(self):
     response = mock_response(json=MagicMock(side_effect=[RUNNING, PROFILE]))
     call_mock = MagicMock(return_value=0)
     with patch('requests.get', MagicMock(return_value=response)), \
             patch('subprocess.call', call_mock), mock_home():
         self.assertEquals(0, ssh_cluster('cluster1', self.config))
     call_mock.assert_called_with(['ssh', '192.168.20.18',
                                   '-l', 'user1',
                                   '-o', 'UserKnownHostsFile=/dev/null',
                                   '-o', 'StrictHostKeyChecking=no',
                                   '-L1:192.168.20.18:1',
                                   '-L2:192.168.20.18:2',
                                   '-L3:192.168.20.18:3'])
     self.assertEmptyIterator(response.json.side_effect)
Exemplo n.º 13
0
 def test_ssh_cluster_with_custom_key(self):
     self.config.ssh_key = '~/.ssh/aws_key'
     response = mock_response(json=MagicMock(
         side_effect=[RUNNING, PROFILE]))
     call_mock = MagicMock(return_value=0)
     with patch('requests.get', MagicMock(return_value=response)), \
             patch('subprocess.call', call_mock), mock_home():
         self.assertEquals(0, ssh_cluster('cluster1', self.config))
     expected_key_path = path.expanduser(self.config.ssh_key)
     call_mock.assert_called_with([
         'ssh', '192.168.20.18', '-l', 'user1', '-o',
         'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no',
         '-L1:192.168.20.18:1', '-L2:192.168.20.18:2',
         '-L3:192.168.20.18:3', '-i', expected_key_path
     ])
Exemplo n.º 14
0
    def test_with_config(self):
        sample_conf = {
            "api_key": "AAAA",
            "api_secret": "BBBB",
            "api_url": "http://localhost/cosmos/v1",
            "ssh": "ssh"
        }
        with mock_home(config=sample_conf):

            def command(args, name, config):
                return "%s-%s" % (name, config.api_key)

            decorated = config.with_config(command)
            self.assertEquals(decorated(self.args, "command1"),
                              "command1-AAAA")
Exemplo n.º 15
0
 def test_ssh_cluster_with_custom_key(self):
     self.config.ssh_key = '~/.ssh/aws_key'
     response = mock_response(json=MagicMock(side_effect=[RUNNING, PROFILE]))
     call_mock = MagicMock(return_value=0)
     with patch('requests.get', MagicMock(return_value=response)), \
             patch('subprocess.call', call_mock), mock_home():
         self.assertEquals(0, ssh_cluster('cluster1', self.config))
     expected_key_path = path.expanduser(self.config.ssh_key)
     call_mock.assert_called_with(['ssh', '192.168.20.18',
                                   '-l', 'user1',
                                   '-o', 'UserKnownHostsFile=/dev/null',
                                   '-o', 'StrictHostKeyChecking=no',
                                   '-L1:192.168.20.18:1',
                                   '-L2:192.168.20.18:2',
                                   '-L3:192.168.20.18:3',
                                   '-i', expected_key_path])
Exemplo n.º 16
0
 def test_config_command(self):
     with mocked_standard_descriptors(self.interactive_configuration), \
             mock_home() as home:
         self.assertEquals(config.command(self.args), 0)
         self.assertIn("api_key: keykeykeyk", home.read_config_file())
Exemplo n.º 17
0
 def test_refuse_ssh_nonexistent_cluster(self):
     response = mock_response(status_code=404)
     with patch('requests.get', MagicMock(return_value=response)), \
             mock_home():
         self.assertRaisesRegexp(ExitWithError, 'cluster1 does not exist',
                                 ssh_cluster, 'cluster1', self.config)
Exemplo n.º 18
0
 def test_config_command(self):
     with mocked_standard_descriptors(self.interactive_configuration), \
             mock_home() as home:
         self.assertEquals(config.command(self.args), 0)
         self.assertIn("api_key: keykeykeyk", home.read_config_file())
Exemplo n.º 19
0
 def test_load_malformed_config(self):
     with mock_home(config="malformed"), collect_outputs() as outputs:
         self.assertRaises(ExitWithError, config.load_config, self.args)
         self.assertIn("Error reading configuration",
                       outputs.stdout.getvalue())
Exemplo n.º 20
0
 def test_load_malformed_config(self):
     with mock_home(config="malformed"), collect_outputs() as outputs:
         self.assertRaises(ExitWithError, config.load_config, self.args)
         self.assertIn("Error reading configuration",
                       outputs.stdout.getvalue())
Exemplo n.º 21
0
 def test_load_no_config(self):
     with mock_home():
         self.assertRaises(ExitWithError, config.load_config, self.args)
Exemplo n.º 22
0
 def test_load_no_config(self):
     with mock_home():
         self.assertRaises(ExitWithError, config.load_config, self.args)