def test_wait_for_tunnel(self, mock_get): acs_info = acsinfo.AcsInfo('myhost', 2200, 'user', 'password', 'pkey', None) acs_client = acsclient.ACSClient(acs_info) self.assertFalse(acs_client.is_running) acs_client._wait_for_tunnel(time.time(), 'wait_for_test') self.assertTrue(acs_client.is_running)
def test_post_request(self, mock_make_request): acs_info = acsinfo.AcsInfo('myhost', 2200, 'user', 'password', 'pkey', 'http://leader.mesos') acs_client = acsclient.ACSClient(acs_info) acs_client.post_request('mypath', post_data='mydata') mock_make_request.assert_called_with('mypath', 'post', data='mydata')
def test_get_request_url_ssh(self, mock_tunnel_server): mock_tunnel_server.return_value = 1234 acs_info = acsinfo.AcsInfo('myhost', 2200, 'user', 'password', 'pkey', None) acs_client = acsclient.ACSClient(acs_info) actual = acs_client.create_request_url('mypath', 8080) self.assertEquals(actual, 'http://127.0.0.1:1234/mypath')
def test_get_private_key_called(self, mock_rsakey): acs_info = acsinfo.AcsInfo('myhost', 2200, None, 'mypassword', 'MYPRIVATEKEY', 'http://leader.mesos') acs_client = acsclient.ACSClient(acs_info) key = acs_client._get_private_key() self.assertIsNotNone(key) self.assertTrue(mock_rsakey.from_private_key.called)
def test_shutdown_not_called(self, mock_current_tunnel): acs_info = acsinfo.AcsInfo('myhost', 2200, 'user', 'password', 'pkey', 'http://leader.mesos') acs_client = acsclient.ACSClient(acs_info) acs_client.shutdown() self.assertFalse(acs_client.is_running) self.assertFalse(mock_current_tunnel[0].stop.called)
def test_make_request_post_200(self, mock_get, mock_request_url): mock_request_url.return_value = 'http://make_request_200' acs_info = acsinfo.AcsInfo('myhost', 2200, 'user', 'password', 'pkey', 'http://leader.mesos') acs_client = acsclient.ACSClient(acs_info) actual = acs_client.make_request('', 'post', data='somedata') self.assertIsNotNone(actual) self.assertEquals(actual.status_code, 200)
def test_setup_tunnel_ssh(self, mock_get_private_key, mock_wait_for_tunnel, mock_tunnel_forwarder, mock_tunnel, mock_available_port): mock_available_port.return_value = '1234' mock_get_private_key.return_value = Mock() acs_info = acsinfo.AcsInfo('myhost', 2200, 'user', 'password', 'pkey', None) acs_client = acsclient.ACSClient(acs_info) return_value = acs_client._setup_tunnel_server(8080) self.assertTrue(mock_available_port.called) self.assertIsNotNone(acs_client.current_tunnel[0]) self.assertEquals(acs_client.current_tunnel[1], 1234) self.assertTrue(mock_tunnel_forwarder.called) self.assertTrue(mock_wait_for_tunnel.called) self.assertEquals(return_value, 1234)
def __init__(self, compose_file, master_url, acs_host, acs_port, acs_username, acs_password, acs_private_key, group_name, group_qualifier, group_version, registry_host, registry_username, registry_password, minimum_health_capacity, check_dcos_version=False): self.cleanup_needed = False self._ensure_docker_compose(compose_file) with open(compose_file, 'r') as compose_stream: self.compose_data = yaml.load(compose_stream) self.acs_info = acsinfo.AcsInfo(acs_host, acs_port, acs_username, acs_password, acs_private_key, master_url) self.group_name = group_name self.group_qualifier = group_qualifier self.group_version = group_version self.registry_host = registry_host self.registry_username = registry_username self.registry_password = registry_password self.minimum_health_capacity = minimum_health_capacity self.acs_client = acsclient.ACSClient(self.acs_info) if check_dcos_version: self.acs_client.ensure_dcos_version() self.marathon_helper = marathon.Marathon(self.acs_client) self.exhibitor_helper = Exhibitor(self.marathon_helper) self.nginx_helper = LoadBalancerApp(self.marathon_helper) self.portmappings_helper = portmappings.PortMappings()
def test_ensure_dcos_version_supported(self, mock_get): acs_info = acsinfo.AcsInfo('myhost', 2200, None, None, None, 'supported_version') acs = acsclient.ACSClient(acs_info) self.assertTrue(acs.ensure_dcos_version())
def test_wait_for_tunnel_fails(self, mock_get): acs_info = acsinfo.AcsInfo('myhost', 2200, 'user', 'password', 'pkey', None) acs_client = acsclient.ACSClient(acs_info) self.assertRaises(Exception, acs_client._wait_for_tunnel, -1, 'wait_for_test_400')
def test_setup_tunnel_direct(self): acs_info = acsinfo.AcsInfo('myhost', 2200, None, None, None, 'http://leader.mesos') acs_client = acsclient.ACSClient(acs_info) self.assertEquals(acs_client._setup_tunnel_server(8080), 8080)
def test_get_private_key_missing(self): acs_info = acsinfo.AcsInfo('myhost', 2200, None, None, None, 'http://leader.mesos') acs_client = acsclient.ACSClient(acs_info) self.assertRaises(Exception, acs_client._get_private_key)
def test_get_private_key_invalidkey(self): acs_info = acsinfo.AcsInfo('myhost', 2200, None, None, 'MYPRIVATEKEY', 'http://leader.mesos') acs_client = acsclient.ACSClient(acs_info) self.assertRaises(paramiko.SSHException, acs_client._get_private_key)
def test_using_ssh_connection(self): acs_info = acsinfo.AcsInfo('myhost', 2200, None, None, None, None) acs_client = acsclient.ACSClient(acs_info) self.assertFalse(acs_client.is_direct)
def test_using_direct_connection(self): acs_info = acsinfo.AcsInfo('myhost', 2200, None, None, None, 'http://leader.mesos') acs_client = acsclient.ACSClient(acs_info) self.assertTrue(acs_client.is_direct)
def test_ensure_dcos_version_missing(self, mock_get): acs_info = acsinfo.AcsInfo('myhost', 2200, None, None, None, 'missing_version') acs = acsclient.ACSClient(acs_info) self.assertRaises(Exception, acs.ensure_dcos_version)
def test_make_request_post_400(self, mock_get, mock_request_url): mock_request_url.return_value = 'http://make_request_400' acs_info = acsinfo.AcsInfo('myhost', 2200, 'user', 'password', 'pkey', 'http://leader.mesos') acs_client = acsclient.ACSClient(acs_info) self.assertRaises(Exception, acs_client.make_request, '', 'post')
def test_ensure_dcos_version_unsupported(self, mock_get): acs_info = acsinfo.AcsInfo('myhost', 2200, None, None, None, 'unsupported_version') acs = acsclient.ACSClient(acs_info) self.assertRaises(ValueError, acs.ensure_dcos_version)