def mocked_aws_cf_simple_backend(monkeypatch, mocked_test_runner): """Does not include SSH key mocking """ monkeypatch.setattr(test_util.aws.DcosCfStack, '__init__', stub(None)) monkeypatch.setattr( test_util.launch, 'fetch_stack', lambda stack_name, bw: test_util.aws.DcosCfStack(stack_name, bw)) # mock create monkeypatch.setattr(test_util.aws.BotoWrapper, 'create_stack', stub(MockStack())) # mock wait monkeypatch.setattr(test_util.aws.CfStack, 'wait_for_complete', stub(None)) # mock describe monkeypatch.setattr(test_util.aws.DcosCfStack, 'get_master_ips', stub([Host('127.0.0.1', '12.34.56')])) monkeypatch.setattr(test_util.aws.DcosCfStack, 'get_private_agent_ips', stub([Host('127.0.0.1', None)])) monkeypatch.setattr(test_util.aws.DcosCfStack, 'get_public_agent_ips', stub([Host('127.0.0.1', '12.34.56')])) # mock delete monkeypatch.setattr(test_util.aws.DcosCfStack, 'delete', stub(None)) monkeypatch.setattr(test_util.aws.BotoWrapper, 'delete_key_pair', stub(None)) # mock config monkeypatch.setattr(test_util.aws.BotoWrapper, 'create_key_pair', stub(MOCK_SSH_KEY_DATA))
def nic_to_host(nic): assert len(nic.ip_configurations) == 1 ip_config = nic.ip_configurations[0] if ip_config.public_ip_address is None: return Host(ip_config.private_ip_address, None) return Host(ip_config.private_ip_address, ip_config.public_ip_address.ip_address)
def get_public_agent_ips(self): """ public traffic is routed to public agents via a specific load balancer """ public_lb_ip = self.public_agent_lb_fqdn return [ Host(nic_to_host(nic).private_ip, public_lb_ip) for nic in self.get_scale_set_nics('public') ]
def mocked_aws_cf_simple_backend(monkeypatch, mocked_test_runner): """Does not include SSH key mocking """ # mock create monkeypatch.setattr(test_util.aws.BotoWrapper, 'create_stack', lambda *args: None) # mock wait monkeypatch.setattr(test_util.aws.CfStack, 'get_stack_details', lambda _: {'StackStatus': 'CREATE_COMPLETE'}) # mock describe monkeypatch.setattr(test_util.aws.DcosCfSimple, 'get_master_ips', lambda _: [Host('127.0.0.1', '12.34.56')]) monkeypatch.setattr(test_util.aws.DcosCfSimple, 'get_private_agent_ips', lambda _: [Host('127.0.0.1', None)]) monkeypatch.setattr(test_util.aws.DcosCfSimple, 'get_public_agent_ips', lambda _: [Host('127.0.0.1', '12.34.56')]) # mock delete monkeypatch.setattr(test_util.aws.DcosCfSimple, 'delete', lambda _: None) monkeypatch.setattr(test_util.aws.BotoWrapper, 'delete_key_pair', lambda *args: None) # mock config monkeypatch.setattr(test_util.aws.BotoWrapper, 'create_key_pair', lambda *args: MOCK_SSH_KEY_DATA)
def get_master_ips(self): """ Traffic from abroad is routed to a master wth the public master loadbalancer FQDN and the VM index plus 2200 (so the first master will be at 2200) """ public_lb_ip = self.public_master_lb_fqdn return [ Host( nic_to_host(nic).private_ip, '{}:{}'.format(public_lb_ip, 2200 + int(nic.name[-1]))) for nic in self.master_nics ]
def mocked_aws_zen_cf(monkeypatch, mocked_aws_cf): monkeypatch.setattr(test_util.aws.DcosZenCfStack, '__init__', stub(None)) monkeypatch.setattr( test_util.aws, 'fetch_stack', lambda stack_name, bw: test_util.aws.DcosZenCfStack(stack_name, bw)) # mock create monkeypatch.setattr(test_util.aws.BotoWrapper, 'create_vpc_tagged', stub(launch.util.MOCK_VPC_ID)) monkeypatch.setattr(test_util.aws.BotoWrapper, 'create_internet_gateway_tagged', stub(launch.util.MOCK_GATEWAY_ID)) monkeypatch.setattr(test_util.aws.BotoWrapper, 'create_subnet_tagged', stub(launch.util.MOCK_SUBNET_ID)) # mock delete monkeypatch.setattr(test_util.aws.BotoWrapper, 'delete_subnet', stub(None)) monkeypatch.setattr(test_util.aws.BotoWrapper, 'delete_vpc', stub(None)) monkeypatch.setattr(test_util.aws.BotoWrapper, 'delete_internet_gateway', stub(None)) # mock describe monkeypatch.setattr(test_util.aws.DcosZenCfStack, 'get_master_ips', stub([Host('127.0.0.1', '12.34.56')])) monkeypatch.setattr(test_util.aws.DcosZenCfStack, 'get_private_agent_ips', stub([Host('127.0.0.1', None)])) monkeypatch.setattr(test_util.aws.DcosZenCfStack, 'get_public_agent_ips', stub([Host('127.0.0.1', '12.34.56')])) # mock delete monkeypatch.setattr(test_util.aws.DcosZenCfStack, 'delete', stub(None))
def instances_to_hosts(instances): return [Host(i.private_ip_address, i.public_ip_address) for i in instances]
def instances_to_hosts(instances): return [ Host(i['PrivateIpAddress'], i['PublicIpAddress'] if 'PublicIpAddress' in i else None) for i in instances ]
monkeypatch.setattr(ssh.ssher.Ssher, 'get_home_dir', stub(b'')) @pytest.fixture def ssh_key_path(tmpdir): ssh_key_path = tmpdir.join('ssh_key') ssh_key_path.write(launch.util.MOCK_SSH_KEY_DATA) return str(ssh_key_path) class MockStack: def __init__(self): self.stack_id = launch.util.MOCK_STACK_ID mock_pub_priv_host = Host('127.0.0.1', '12.34.56') mock_priv_host = Host('127.0.0.1', None) @pytest.fixture def mocked_aws_cf(monkeypatch, mocked_test_runner): """Does not include SSH key mocking """ monkeypatch.setattr(test_util.aws.DcosCfStack, '__init__', stub(None)) monkeypatch.setattr( test_util.aws, 'fetch_stack', lambda stack_name, bw: test_util.aws.DcosCfStack(stack_name, bw)) # mock create monkeypatch.setattr(test_util.aws.BotoWrapper, 'create_stack', stub(MockStack())) # mock wait monkeypatch.setattr(test_util.aws.CfStack, 'wait_for_complete', stub(None)) # mock describe