def test_0060_attach_port_group(self): """Attach a portgroup to an external network This test passes if the portgroup from another vCenter is added to external network successfully. """ if TestExtNet._vc2_host_ip is None or TestExtNet._vc2_host_ip == '': return logger = Environment.get_default_logger() platform = Platform(TestExtNet._sys_admin_client) vc_name = TestExtNet._config['vc2']['vcenter_host_name'] portgrouphelper = PortgroupHelper(TestExtNet._sys_admin_client) pg_name = portgrouphelper.get_available_portgroup_name( vc_name, TestExtNet._portgroupType) ext_net = self._get_ext_net(platform).attach_port_group( vc_name, pg_name) task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0] TestExtNet._sys_admin_client.get_task_monitor().wait_for_success( task=task) logger.debug( 'Attach a portgroup to an external network' + TestExtNet._name + '.') ext_net = platform.get_external_network(self._name) self.assertIsNotNone(ext_net) vc_record = platform.get_vcenter(vc_name) vc_href = vc_record.get('href') vim_port_group_refs = \ ext_net['{' + NSMAP['vmext'] + '}VimPortGroupRefs'] vc_href_found = False for vim_obj_ref in vim_port_group_refs.VimObjectRef: if vim_obj_ref.VimServerRef.get('href') == vc_href: vc_href_found = True break self.assertTrue(vc_href_found)
def test_0061_detach_port_group(self): """Detach a portgroup from an external network This test passes if the portgroup from another vCenter is removed from external network successfully. """ if TestExtNet._vc2_host_ip is None or TestExtNet._vc2_host_ip == '': return logger = Environment.get_default_logger() platform = Platform(TestExtNet._sys_admin_client) vc_name = TestExtNet._config['vc2']['vcenter_host_name'] port_group_helper = PortgroupHelper(TestExtNet._sys_admin_client) pg_name = port_group_helper.get_ext_net_portgroup_name(vc_name, self._name) ext_net = self._get_ext_net(platform).detach_port_group(vc_name, pg_name) task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0] TestExtNet._sys_admin_client.get_task_monitor().wait_for_success( task=task) logger.debug( 'Detach a portgroup from an external network' + TestExtNet._name) ext_net = platform.get_external_network(self._name) self.assertIsNotNone(ext_net) vc_record = platform.get_vcenter(vc_name) vc_href = vc_record.get('href') vim_port_group_ref = ext_net.VimPortGroupRef vc_href_found = False if vim_port_group_ref.VimServerRef.get('href') == vc_href: vc_href_found = True self.assertFalse(vc_href_found)
def test_0061_detach_port_group(self): """Detach a portgroup from an external network This test passes if the portgroup from another vCenter is removed from external network successfully. """ if TestExtNet._vc2_host_ip is None or TestExtNet._vc2_host_ip == '': return logger = Environment.get_default_logger() platform = Platform(TestExtNet._sys_admin_client) vc_name = TestExtNet._config['vc2']['vcenter_host_name'] port_group_helper = PortgroupHelper(TestExtNet._sys_admin_client) pg_name = port_group_helper.get_ext_net_portgroup_name( vc_name, self._name) ext_net = self._get_ext_net(platform).detach_port_group( vc_name, pg_name) task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0] TestExtNet._sys_admin_client.get_task_monitor().wait_for_success( task=task) logger.debug('Detach a portgroup from an external network' + TestExtNet._name) ext_net = platform.get_external_network(self._name) self.assertIsNotNone(ext_net) vc_record = platform.get_vcenter(vc_name) vc_href = vc_record.get('href') vim_port_group_ref = ext_net.VimPortGroupRef vc_href_found = False if vim_port_group_ref.VimServerRef.get('href') == vc_href: vc_href_found = True self.assertFalse(vc_href_found)
def test_0060_attach_port_group(self): """Attach a portgroup to an external network This test passes if the portgroup from another vCenter is added to external network successfully. """ if TestExtNet._vc2_host_ip is None or TestExtNet._vc2_host_ip == '': return logger = Environment.get_default_logger() platform = Platform(TestExtNet._sys_admin_client) vc_name = TestExtNet._config['vc2']['vcenter_host_name'] portgrouphelper = PortgroupHelper(TestExtNet._sys_admin_client) pg_name = portgrouphelper.get_available_portgroup_name( vc_name, TestExtNet._portgroupType) ext_net = self._get_ext_net(platform).attach_port_group( vc_name, pg_name) task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0] TestExtNet._sys_admin_client.get_task_monitor().wait_for_success( task=task) logger.debug('Attach a portgroup to an external network' + TestExtNet._name + '.') ext_net = platform.get_external_network(self._name) self.assertIsNotNone(ext_net) vc_record = platform.get_vcenter(vc_name) vc_href = vc_record.get('href') vim_port_group_refs = \ ext_net['{' + NSMAP['vmext'] + '}VimPortGroupRefs'] vc_href_found = False for vim_obj_ref in vim_port_group_refs.VimObjectRef: if vim_obj_ref.VimServerRef.get('href') == vc_href: vc_href_found = True break self.assertTrue(vc_href_found)
def test_0000_setup(self): """ Create one external network as per the configuration stated aboveself. Choose first unused port group which is not a VxLAN. Unused port groups have network names set to '--'. VxLAN port groups have name starting with 'vxw-'. Test the method Platform.create_external_network(). This test passes if external network is created successfully. """ logger = Environment.get_default_logger() TestExtNet._sys_admin_client = Environment.get_sys_admin_client() TestExtNet._config = Environment.get_config() TestExtNet._common_ext_net_name = TestExtNet._config[ 'external_network']['name'] platform = Platform(TestExtNet._sys_admin_client) vc_name = TestExtNet._config['vc']['vcenter_host_name'] TestExtNet._vc2_host_ip = TestExtNet._config['vc2']['vcenter_host_ip'] portgrouphelper = PortgroupHelper(TestExtNet._sys_admin_client) pg_name = portgrouphelper.get_available_portgroup_name( vc_name, TestExtNet._portgroupType) ext_net = platform.create_external_network( name=TestExtNet._name, vim_server_name=vc_name, port_group_names=[pg_name], gateway_ip=TestExtNet._gateway, netmask=TestExtNet._netmask, ip_ranges=[TestExtNet._ip_range], description=TestExtNet._description, primary_dns_ip=TestExtNet._dns1, secondary_dns_ip=TestExtNet._dns2, dns_suffix=TestExtNet._dns_suffix) task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0] TestExtNet._sys_admin_client.get_task_monitor().wait_for_success( task=task) logger.debug('Created external network ' + TestExtNet._name + '.')
def test_0000_setup(self): """ Create one external network as per the configuration stated aboveself. Choose first unused port group which is not a VxLAN. Unused port groups have network names set to '--'. VxLAN port groups have name starting with 'vxw-'. Test the method Platform.create_external_network(). This test passes if external network is created successfully. """ logger = Environment.get_default_logger() TestExtNet._sys_admin_client = Environment.get_sys_admin_client() TestExtNet._config = Environment.get_config() TestExtNet._common_ext_net_name = TestExtNet._config[ 'external_network']['name'] platform = Platform(TestExtNet._sys_admin_client) vc_name = TestExtNet._config['vc']['vcenter_host_name'] TestExtNet._vc2_host_ip = TestExtNet._config['vc2']['vcenter_host_ip'] portgrouphelper = PortgroupHelper(TestExtNet._sys_admin_client) pg_name = portgrouphelper.get_available_portgroup_name( vc_name, TestExtNet._portgroupType) ext_net = platform.create_external_network( name=TestExtNet._name, vim_server_name=vc_name, port_group_names=[pg_name], gateway_ip=TestExtNet._gateway, netmask=TestExtNet._netmask, ip_ranges=[TestExtNet._ip_range], description=TestExtNet._description, primary_dns_ip=TestExtNet._dns1, secondary_dns_ip=TestExtNet._dns2, dns_suffix=TestExtNet._dns_suffix) task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0] TestExtNet._sys_admin_client.get_task_monitor().wait_for_success( task=task) logger.debug('Created external network ' + TestExtNet._name + '.')
def _create_external_network(cls): vc_name = cls._config['vc']['vcenter_host_name'] portgrouphelper = PortgroupHelper(cls._sys_admin_client) port_group = portgrouphelper.get_available_portgroup_name( vc_name, Environment._portgroupType) if port_group is None: raise Exception( 'None of the port groups are free for new network.') ext_config = cls._config['external_network'] ip_scopes = cls._config['external_network']['ip_scopes'] if len(ip_scopes) == 0: raise Exception('No network spec provided.') # [{subnet:'10.10.10.1/24', ip_range:'10.10.10.101-10.10.10.150'}] primary_subnet = ip_scopes[0]['subnet'] gateway_ip, prefix_len = primary_subnet.split('/') netmask = cidr_to_netmask(primary_subnet)[1] ip_ranges = ip_scopes[0]['ip_ranges'] primary_dns_ip = '8.8.8.8' secondary_dns_ip = '8.8.8.9' dns_suffix = 'example.com' platform = Platform(cls._sys_admin_client) ext_net = platform.create_external_network( name=ext_config['name'], vim_server_name=vc_name, port_group_names=[port_group], gateway_ip=gateway_ip, netmask=netmask, ip_ranges=ip_ranges, description=ext_config['name'], primary_dns_ip=primary_dns_ip, secondary_dns_ip=secondary_dns_ip, dns_suffix=dns_suffix) task = ext_net['{' + NSMAP['vcloud'] + '}Tasks'].Task[0] cls._sys_admin_client.get_task_monitor().wait_for_success(task=task) return ext_net
def test_0041_detach_port_group(self): """Detach port group from an external network. Invoke the command 'external detach-port-group' in network. """ ExtNetTest._client = Environment.get_sys_admin_client() port_group_helper = PortgroupHelper(ExtNetTest._client) vc_name = self._config['vc2']['vcenter_host_name'] pg_name = port_group_helper. \ get_ext_net_used_portgroup_name(vc_name, self._name) result = self._runner.invoke(external, args=[ 'detach-port-group', self._name, '--vc-name', vc_name, '--port-group', pg_name ]) self.assertEqual(0, result.exit_code)
def test_0040_attach_port_group(self): """Attach a portgroup to an external network. Invoke the command 'external attach-port-group' in network. """ ExtNetTest._client = Environment.get_sys_admin_client() port_group_helper = PortgroupHelper(ExtNetTest._client) vc_name = self._config['vc2']['vcenter_host_name'] pg_name = port_group_helper. \ get_available_portgroup_name(vc_name, ExtNetTest._portgroupType) result = self._runner.invoke(external, args=[ 'attach-port-group', self._name, '--vc-name', vc_name, '--port-group', pg_name ]) self.assertEqual(0, result.exit_code)