def check_useras(testcase, user_as, attachment_point, owner, use_vpn, public_ip, public_port, bind_ip, bind_port, installation_type, label): """ Check the state of `user_as`. Verify that a link to the attachment point exists and that it is configured according to the given parameters. """ testcase.assertEqual(user_as.owner, owner) testcase.assertEqual(user_as.label, label) testcase.assertEqual(user_as.installation_type, installation_type) testcase.assertEqual(user_as.attachment_point, attachment_point) testcase.assertEqual(user_as.is_use_vpn(), use_vpn) testcase.assertEqual(user_as.public_ip, public_ip) testcase.assertEqual(user_as.get_public_port(), public_port) testcase.assertEqual(user_as.bind_ip, bind_ip) testcase.assertEqual(user_as.bind_port, bind_port) utils.check_as(testcase, user_as) utils.check_as(testcase, attachment_point.AS) link = get_provider_link(attachment_point.AS, user_as) if use_vpn: utils.check_link( testcase, link, utils.LinkDescription( type=Link.PROVIDER, from_as_id=attachment_point.AS.as_id, from_public_ip=attachment_point.vpn.server_vpn_ip(), from_bind_ip=None, from_internal_ip=DEFAULT_HOST_INTERNAL_IP, to_public_ip=user_as.hosts.get().vpn_clients.get( active=True).ip, to_public_port=public_port, to_bind_ip=None, to_bind_port=None, to_internal_ip=DEFAULT_HOST_INTERNAL_IP, )) else: utils.check_link( testcase, link, utils.LinkDescription( type=Link.PROVIDER, from_as_id=attachment_point.AS.as_id, from_public_ip=_get_public_ip_testtopo( attachment_point.AS.as_id), from_bind_ip=None, from_internal_ip=DEFAULT_HOST_INTERNAL_IP, to_public_ip=public_ip, to_public_port=public_port, to_bind_ip=bind_ip, to_bind_port=bind_port, to_internal_ip=DEFAULT_HOST_INTERNAL_IP, ))
def test_create_as_with_default_services(self): isd = ISD.objects.create(isd_id=17, label='Switzerland') AS.objects.create(isd=isd, as_id='ff00:1:1', is_core=True) as_ = AS.objects.create_with_default_services(isd=isd, as_id='ff00:1:2', public_ip='192.0.2.11') self.assertTrue(hasattr(as_, 'hosts')) self.assertEqual(as_.hosts.count(), 1) host = as_.hosts.first() self.assertEqual(host.internal_ip, "127.0.0.1") self.assertTrue(host.needs_config_deployment()) self.assertTrue(hasattr(host, 'services')) self.assertEqual(sorted(s.type for s in host.services.iterator()), ['CO', 'CS']) utils.check_as(self, as_)
def check_useras(testcase, user_as: UserAS, att_confs: List[AttachmentConf], owner, vpn_choice: VPNChoice, installation_type, label, **kwargs): """ Check the state of `user_as` and `att_confs`. Verify that the links to the attachment points exists and that they are configured according to the given parameters. """ testcase.assertEqual(user_as.owner, owner) testcase.assertEqual(user_as.label, label) testcase.assertEqual(user_as.installation_type, installation_type) utils.check_as(testcase, user_as) # Check that the AttachmentPoints in `att_confs` are now AttachmentPoints of the user_as aps_ases = [c.attachment_point.AS for c in att_confs] user_as_aps_ases = [ link.interfaceA.AS for link in Link.objects.filter(interfaceB__AS=user_as).all() ] testcase.assertEqual(sorted(user_as_aps_ases, key=lambda _as: _as.id), sorted(aps_ases, key=lambda _as: _as.id)) # Check attachment points configuration for att_conf in filter(lambda att_conf: att_conf.active, att_confs): ap = att_conf.attachment_point utils.check_as(testcase, ap.AS) _check_attachment_point(testcase, ap) link = att_conf.link testcase.assertEqual(att_conf.active, link.active) testcase.assertEqual(att_conf.public_port, link.interfaceB.public_port) if att_conf.use_vpn: testcase.assertNotEqual(vpn_choice, VPNChoice.NONE) testcase.assertTrue( VPNClient.objects.filter(host=user_as.host, vpn=ap.vpn).exists()) utils.check_link( testcase, link, utils.LinkDescription( type=Link.PROVIDER, from_as_id=ap.AS.as_id, from_public_ip=ap.vpn.server_vpn_ip, from_bind_ip=None, from_internal_ip=DEFAULT_HOST_INTERNAL_IP, to_public_ip=user_as.hosts.get().vpn_clients.get( active=True, vpn=ap.vpn).ip, to_public_port=att_conf.public_port, to_bind_ip=None, to_bind_port=None, to_internal_ip=DEFAULT_HOST_INTERNAL_IP, )) else: testcase.assertNotEqual(vpn_choice, VPNChoice.ALL) vpn_client = VPNClient.objects.filter( host=user_as.host, vpn=att_conf.attachment_point.vpn).first() testcase.assertTrue(not vpn_client or not vpn_client.active) bind_ip, bind_port = att_conf.bind_ip, att_conf.bind_port if installation_type == UserAS.VM: bind_ip = '10.0.2.15' if bind_port is None: # Port is assigned automatically in this case, so we cannot know it in advance # XXX: Actually in this case the test check is skipped, but it shouldn't be # a problem since we would just be testing whether or not PortMap is working, # which has its own tests bind_port = att_conf.link.interfaceB.bind_port utils.check_link( testcase, link, utils.LinkDescription( type=Link.PROVIDER, from_as_id=ap.AS.as_id, from_public_ip=_get_public_ip_testtopo(ap.AS.as_id), from_bind_ip=None, from_internal_ip=DEFAULT_HOST_INTERNAL_IP, to_public_ip=att_conf.public_ip, to_public_port=att_conf.public_port, to_bind_ip=bind_ip, to_bind_port=bind_port, to_internal_ip=DEFAULT_HOST_INTERNAL_IP, ))
def check_useras(testcase, user_as: UserAS, att_confs: List[AttachmentConf], owner, vpn_choice: VPNChoice, installation_type, label, is_ap, public_ip, wants_vpn, **kwargs): """ Check the state of `user_as` and `att_confs`. Verify that the links to the attachment points exists and that they are configured according to the given parameters. """ testcase.assertEqual(user_as.owner, owner) testcase.assertEqual(user_as.label, label) testcase.assertEqual(user_as.installation_type, installation_type) testcase.assertEqual(user_as.is_attachment_point(), is_ap) if is_ap: ap = user_as.attachment_point_info host = user_as.hosts.first() testcase.assertEqual(host.public_ip, public_ip) testcase.assertEqual(ap.vpn is not None, wants_vpn) utils.check_as(testcase, user_as) # Check that the AttachmentPoints in `att_confs` are now AttachmentPoints of the user_as aps_ases = [c.attachment_point.AS for c in att_confs] user_as_aps_ases = [ link.interfaceA.AS for link in Link.objects.filter(interfaceB__AS=user_as).all() ] testcase.assertEqual(sorted(user_as_aps_ases, key=lambda _as: _as.id), sorted(aps_ases, key=lambda _as: _as.id)) # Check attachment points configuration for att_conf in filter(lambda att_conf: att_conf.active, att_confs): ap = att_conf.attachment_point utils.check_as(testcase, ap.AS) _check_attachment_point(testcase, ap) link = att_conf.link testcase.assertEqual(att_conf.active, link.active) testcase.assertEqual(att_conf.public_port, link.interfaceB.public_port) if att_conf.use_vpn: testcase.assertNotEqual(vpn_choice, VPNChoice.NONE) testcase.assertTrue( VPNClient.objects.filter(host=user_as.host, vpn=ap.vpn).exists()) utils.check_link( testcase, link, utils.LinkDescription( type=Link.PROVIDER, from_as_id=ap.AS.as_id, from_public_ip=ap.vpn.server_vpn_ip, from_bind_ip=None, from_internal_ip=DEFAULT_HOST_INTERNAL_IP, to_public_ip=user_as.hosts.get().vpn_clients.get( active=True, vpn=ap.vpn).ip, to_public_port=att_conf.public_port, to_bind_ip=None, to_internal_ip=DEFAULT_HOST_INTERNAL_IP, )) else: testcase.assertNotEqual(vpn_choice, VPNChoice.ALL) vpn_client = VPNClient.objects.filter( host=user_as.host, vpn=att_conf.attachment_point.vpn).first() testcase.assertTrue(not vpn_client or not vpn_client.active) bind_ip = att_conf.bind_ip if installation_type == UserAS.VM: bind_ip = '10.0.2.15' utils.check_link( testcase, link, utils.LinkDescription( type=Link.PROVIDER, from_as_id=ap.AS.as_id, from_public_ip=_get_public_ip_testtopo(ap.AS.as_id), from_bind_ip=None, from_internal_ip=DEFAULT_HOST_INTERNAL_IP, to_public_ip=att_conf.public_ip, to_public_port=att_conf.public_port, to_bind_ip=bind_ip, to_internal_ip=DEFAULT_HOST_INTERNAL_IP, ))