How to use _get_dns_servers method in tempest

Best Python code snippet using tempest_python

networkmanager.py

Source:networkmanager.py Github

copy

Full Screen

...160 for line in fields:161 if line.startswith('HWaddr'):162 unused, hwaddr = line.split(None, 1)163 return hwaddr164 def _get_dns_servers(self):165 try:166 resolv = open('/etc/resolv.conf')167 servers = [line.strip().split(None, 1)[1] for line in resolv if line.startswith('nameserver')]168 resolv.close()169 if not servers:170 servers = ['0.0.0.0', '0.0.0.0']171 except IOError:172 servers = ['0.0.0.0', '0.0.0.0']173 return servers174 # Update the object data by parsing 'ifconfig' and 'route' commands175 def _get_network_infos(self, ifname):176 _ip = '0.0.0.0'177 _hwaddr = '00:00:00:00:00:00'178 _netmask = '0.0.0.0'179 _gateway = '0.0.0.0'180 ifconfig = os.popen('/sbin/ifconfig')181 raw = ifconfig.read()182 ifconfig.close()183 data = [line for line in raw.split('\n\n') if line.startswith(ifname + ' ')]184 if not data:185 raise ValueError('The interface %s does not exist' % ifname)186 fields = filter(bool, (line.strip() for line in data[0].split(' ')))187 for line in fields:188 if line.startswith('inet addr'):189 unused, _ip = line.split(':', 1)190 elif line.startswith('Mask'):191 unused, _netmask = line.split(':', 1)192 route = os.popen('/sbin/route -n')193 raw = route.read()194 route.close()195 data = [line for line in raw.split('\n') if line.startswith('0.0.0.0 ') and line.endswith(ifname)]196 if data:197 fields = data[0].split(None, 2)198 _gateway = fields[1]199 dns_servs = self._get_dns_servers()200 if len(dns_servs) == 1:201 dns_servs.append('0.0.0.0')202 return {'ip': _ip, 'netmask': _netmask, 'hwaddr': _hwaddr, 'gateway': _gateway, 'dns1': dns_servs[0], 'dns2': dns_servs[1]}203 def get_active_configuration(self):204 try:205 for config in self.pynet.getConfigurations():206 params = self.pynet.getConfiguration(config)207 if params[0]:208 if params[3] == 'upnp':209 infos = self._get_network_infos(params[1])210 params[4] = infos['ip']211 params[5] = infos['netmask']212 params[6] = infos['gateway']213 params[7] = infos['dns1']...

Full Screen

Full Screen

remote_client.py

Source:remote_client.py Github

copy

Full Screen

...90 cmd = "ip -o addr | awk '/%s/ {print $2}'" % address91 nic = self.exec_command(cmd)92 LOG.debug('(get_nic_name_by_ip) Command result: %s', nic)93 return nic.strip().strip(":").split('@')[0].lower()94 def _get_dns_servers(self):95 cmd = 'cat /etc/resolv.conf'96 resolve_file = self.exec_command(cmd).strip().split('\n')97 entries = (l.split() for l in resolve_file)98 dns_servers = [l[1] for l in entries99 if len(l) and l[0] == 'nameserver']100 return dns_servers101 def get_dns_servers(self, timeout=5):102 start_time = int(time.time())103 dns_servers = []104 while True:105 dns_servers = self._get_dns_servers()106 if dns_servers:107 break108 LOG.debug("DNS Servers list empty.")109 if int(time.time()) - start_time >= timeout:110 LOG.debug("DNS Servers list empty after %s.", timeout)111 break112 return dns_servers113 def _renew_lease_udhcpc(self, fixed_ip=None):114 """Renews DHCP lease via udhcpc client. """115 file_path = '/var/run/udhcpc.'116 nic_name = self.get_nic_name_by_ip(fixed_ip)117 pid = self.exec_command('cat {path}{nic}.pid'.118 format(path=file_path, nic=nic_name))119 pid = pid.strip()...

Full Screen

Full Screen

nsxt.py

Source:nsxt.py Github

copy

Full Screen

...50 return ret['ip_address']51 def _get_cluster_uuid(self):52 ret = self.get(urisuffix='/api/v1/cluster')53 return ret['cluster_id']54 def _get_dns_servers(self):55 ret = self.get(urisuffix='/api/v1/node/network/name-servers')56 return ret['name_servers']57 def _get_dns_domains(self):58 ret = self.get(urisuffix='/api/v1/node/network/search-domains')59 return ret['search_domains']60 def _get_ntp_servers(self):61 ret = self.get(urisuffix='/api/v1/node/services/ntp')62 return ret['service_properties']['servers']63 def _get_ssh_service(self):64 ret = self.get(urisuffix='/api/v1/node/services/ssh')65 return ret['service_properties']['start_on_boot']66 def get_cluster_wide_configs(self):67 return {68 'vip': self._get_cluster_vip(),69 'cluster_uuid': self._get_cluster_uuid(),70 'dns_servers': self._get_dns_servers(),71 'search_domains': self._get_dns_domains(),72 'ntp_servers': self._get_ntp_servers(),73 'ssh_auto_start': self._get_ssh_service()74 }75 def get_mgmt_nodes_configs(self):76 mgmt_nodes_configs = []77 ret = self.get(urisuffix='/api/v1/cluster')78 for mgmt_node in ret['nodes']:79 mgmt_nodes_configs.append({80 'fqdn': mgmt_node['fqdn'],81 'uuid': mgmt_node['node_uuid'],82 'ip_address': mgmt_node['entities'][0]['ip_address']83 })84 return mgmt_nodes_configs...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful