def __init__(self, filename=None, data=None): super(PhysicalTopologyManager, self).__init__(filename, data) self._hosts = self._data['physical_topology'].get('hosts') self._compute_hosts = service.get_all_containers('midolman') self._external_hosts = service.get_all_containers('externalhost') self._bridges = self._data['physical_topology'].get('bridges') or [] self._interfaces = {} # (host_id, interface_id) to interface map
def _get_all_services(self): flat_services = [] services = service.get_all_containers(include_failed=True) for service_type, service_hosts in services.items(): for service_host in service_hosts: flat_services.append(service_host) return flat_services
def setup_package(): """ Setup method at the tests module level (init) :return: """ # Check all services (including midolman) are online api_host = service.get_container_by_hostname('cluster1') api_host.wait_for_status('up') for type, hosts in service.get_all_containers().items(): for host in hosts: LOG.debug("Checking liveness of %s" % host.get_hostname()) host.wait_for_status('up', timeout=conf.service_status_timeout()) # Wait until bindings do not fail, at that point, mdts is ready for test max_attempts = 10 for current_attempts in xrange(max_attempts): topology = build_simple_topology() try: destroy_simple_topology(topology) LOG.debug("MDTS ready to run tests.") return except: destroy_simple_topology(topology) current_attempts += 1 LOG.debug("MDTS failed to bind port... check again. Attempt: %d" % current_attempts) raise RuntimeError("MDTS was unable to bind a single port... Exiting.")
def setup_package(): """ Setup method at the tests module level (init) :return: """ # Read configuration conf_file = os.getenv('MDTS_CONF_FILE', 'mdts.conf') config = SafeConfigParser() config.read(conf_file) # Check all services (including midolman) are online api_host = service.get_container_by_hostname('cluster1') api_host.wait_for_status('up') for type, hosts in service.get_all_containers().items(): for host in hosts: LOG.debug("Checking liveness of %s" % host.get_hostname()) host.wait_for_status('up', timeout=240) # Wait until bindings do not fail, at that point, mdts is ready for test max_attempts = 10 for current_attempts in xrange(max_attempts): topology = build_simple_topology() try: destroy_simple_topology(topology) LOG.debug("MDTS ready to run tests.") return except: destroy_simple_topology(topology) current_attempts += 1 LOG.debug("MDTS failed to bind port... check again. Attempt: %d" % current_attempts) raise RuntimeError("MDTS was unable to bind a single port... Exiting.")
def test_host_status(): """ Title: Test host status update Scenario: When: The test starts up, Then: check if all Midolman agents are alive, Then: stops all Midolman agents, Then: check if all Midolman agents are now dead, Then: restarts all Midolman agetns, And: check again if all Midolman agents are alive, """ agents = service.get_all_containers('midolman') for agent in agents: assert agent.get_service_status() == 'up' for agent in agents: agent.stop(wait=True) for agent in agents: assert agent.get_service_status() == 'down' for agent in agents: agent.start(wait=True) # FIXME: remove this timeout if tests pass # time.sleep(30) for agent in agents: assert agent.get_service_status() == 'up'
def _get_all_services(self): flat_services = [] services = service.get_all_containers() for service_type, service_hosts in services.items(): for service_host in service_hosts: flat_services.append(service_host) return flat_services
def beforeTest(self, test): import ipdb;ipdb.set_trace() """Inserts merker to the MM logs""" marker = self._get_markers_for_test(test.id())['start'] midolman_hosts = service.get_all_containers('midolman') for midolman in midolman_hosts: midolman.set_log_marker(marker)
def finalize(self, result): """Finally modify xunit xml file by adding only relevant midolmlan logs for failed or errored tests""" if os.path.exists(self.xunit_file): tree = ET.parse(self.xunit_file) root = tree.getroot() for test_case in root: test_id = test_case.get( 'classname') + '.' + test_case.get('name') failure = test_case.find('failure') if failure is not None: failure.text += '\n' midolman_hosts = service.get_all_containers('midolman') markers = self._get_markers_for_test(test_id) for midolman in midolman_hosts: midolman_log = midolman.get_test_log(markers['start'], markers['end']) failure.text += midolman_log #failure.text += self._get_midolman_logs_for_test( # test_id).replace('\0', '') error = test_case.find('error') if error is not None: error.text += '\n' error.text += self._get_midolman_logs_for_test( test_id).replace('\0', '') tree.write(self.xunit_file)
def _write_per_test_debug_info(self, test, result): test_id = test.id() #test_id = "%s.%s" % (test_case.get('classname'), # test_case.get('name')) dump_dir = "%s/%s" % (self.log_dir, test_id) if not os.path.exists(dump_dir): os.makedirs(dump_dir) # Any midolman works for us in here. # FIXME: should be zk maybe? whatever works but still midolman = service.get_container_by_hostname('midolman1') zkdump_output = midolman.exec_command( 'zkdump -z zookeeper1:2181 -d -p') with open("%s/zkdump_output.log" % dump_dir, 'w') as f: f.write(zkdump_output) midolmans = service.get_all_containers('midolman') for midolman in midolmans: mmdpctl_show = midolman.exec_command( 'mm-dpctl --timeout 10 datapath --show midonet') mmdpctl_dump = midolman.exec_command( 'mm-dpctl --timeout 10 datapath --dump midonet') service_dir = "%s/%s" % (dump_dir, midolman.get_hostname()) if not os.path.exists(service_dir): os.makedirs(service_dir) with open("%s/mmdpctl_output.log" % service_dir, 'w') as f: f.write("------------------------------------------------\n") f.write("mm-dpctl --timeout 10 datapath --show midonet \n") f.write("------------------------------------------------\n") f.write(mmdpctl_show) f.write("------------------------------------------------\n\n") f.write("------------------------------------------------\n") f.write("mm-dpctl --timeout 10 datapath --dump midonet \n") f.write("------------------------------------------------\n") f.write(mmdpctl_dump)
def test_host_status(): """ mdts.tests.functional_tests.test_midolman_and_interfaces.test_host_status Scenario: When: The test starts up, Then: check if all Midolman agents are alive, Then: stops all Midolman agents, Then: check if all Midolman agents are now dead, Then: restarts all Midolman agetns, And: check again if all Midolman agents are alive, """ agents = service.get_all_containers('midolman') for agent in agents: assert agent.get_service_status() == 'up' for agent in agents: agent.stop(wait=True) for agent in agents: assert agent.get_service_status() == 'down' for agent in agents: agent.start(wait=True) for agent in agents: assert agent.get_service_status() == 'up'
def get_current_leader(lb_pools, timeout = 60, wait_time=5): agents = service.get_all_containers('midolman') current_leader = None num_leaders = 0 haproxies = [] while timeout > 0: for agent in agents: # Check that we have an haproxy running for each pool to be # considered a full leader haproxies = [] for lb_pool in lb_pools: if agent.hm_resources_exist(lb_pool.get_id()): haproxies.append(lb_pool.get_id()) else: break if len(haproxies) == len(lb_pools): current_leader = agent num_leaders += 1 assert_that(num_leaders <= 1, True, 'L4LB: More than one agent running haproxy instances') if num_leaders == 0: LOG.debug('L4LB: No haproxy leaders found! Retrying...') time.sleep(wait_time) timeout -= wait_time else: LOG.debug('L4LB: current leader is %s' % current_leader.get_hostname()) return current_leader raise RuntimeError('Not all haproxy instances found! ' 'Only pools %s have an haproxy instance.' % haproxies)
def test_host_status(): """ mdts.tests.functional_tests.test_midolman_and_interfaces.test_host_status Scenario: When: The test starts up, Then: check if all Midolman agents are alive, Then: stops all Midolman agents, Then: check if all Midolman agents are now dead, Then: restarts all Midolman agetns, And: check again if all Midolman agents are alive, """ agents = service.get_all_containers('midolman') for agent in agents: assert agent.get_service_status() == 'up' for agent in agents: agent.stop(wait=True) for agent in agents: assert agent.get_service_status() == 'down' for agent in agents: agent.start(wait=True) for agent in agents: assert agent.get_service_status() == 'up'
def destroy(self): LOG.debug('-' * 80) LOG.debug("destroy") LOG.debug('-' * 80) midonet_api_host = service.get_all_containers(container_type='midonet-api')[0] midonet_api = midonet_api_host.get_midonet_api() tzs = midonet_api.get_tunnel_zones() mdts_tzs = filter(lambda t: t.get_name() == 'mdts-test', tzs) map(lambda tz: tz.delete(), mdts_tzs) # for h in self._hosts: # host = h['host'] # # # Delete TZ # if host.get('tunnel_zone'): # tz_data = host.get('tunnel_zone') # tzs = self._api.get_tunnel_zones() # tz = filter(lambda x: x.get_name() == tz_data['name'], tzs) # # Delete tz, which has(have) the name in the config # map(lambda x: x.delete(), tz) # # if host['provided'] == True: # LOG.info('Skipped destroying host=%r', host) # else: # #TODO(tomoe): when we support provisioning Midolman host with # # this tool. # pass # interfaces = host['interfaces'] # # futures = [] # for i in interfaces: # iface = Interface(i['interface'], host) # f = iface.delete() # futures.append(f) # # wait_on_futures(futures) # # for b in self._bridges: # bridge = b['bridge'] # # TODO(tomohiko) Need to do something when !host['provided']? # if host['provided']: # LOG.info('Skipped destroying bridge=%r', bridge) LOG.debug('-' * 80) LOG.debug("end destroy") LOG.debug('-' * 80)
def _write_per_test_debug_info(self, test, result): test_id = test.id() #test_id = "%s.%s" % (test_case.get('classname'), # test_case.get('name')) dump_dir = "%s/%s" % (self.log_dir, test_id) if not os.path.exists(dump_dir): os.makedirs(dump_dir) # Any midolman works for us in here. # FIXME: should be zk maybe? whatever works but still midolmans = service.get_all_containers('midolman') if len(midolmans) > 0: midolman = midolmans[0] zkdump_output = midolman.exec_command( 'zkdump -z zookeeper1:2181 -d -p') with open("%s/zkdump_output.log" % dump_dir, 'w') as f: f.write(zkdump_output) for midolman in midolmans: mmdpctl_show = midolman.exec_command( 'mm-dpctl --timeout 10 datapath --show midonet') mmdpctl_dump = midolman.exec_command( 'mm-dpctl --timeout 10 datapath --dump midonet') service_dir = "%s/%s" % (dump_dir, midolman.get_hostname()) if not os.path.exists(service_dir): os.makedirs(service_dir) with open("%s/mmdpctl_output.log" % service_dir, 'w') as f: f.write("------------------------------------------------\n") f.write("mm-dpctl --timeout 10 datapath --show midonet \n") f.write("------------------------------------------------\n") f.write(mmdpctl_show) f.write("------------------------------------------------\n\n") f.write("------------------------------------------------\n") f.write("mm-dpctl --timeout 10 datapath --dump midonet \n") f.write("------------------------------------------------\n") f.write(mmdpctl_dump)
def setup_mdts(max_attempts): # Check all services (including midolman) are online api_host = service.get_container_by_hostname('cluster1') api_host.wait_for_status('up') for type, hosts in service.get_all_containers().items(): for host in hosts: LOG.debug("Checking liveness of %s" % host.get_hostname()) host.wait_for_status('up', timeout=conf.service_status_timeout()) # Wait until bindings do not fail, at that point, mdts is ready for test for current_attempts in xrange(max_attempts): topology = build_simple_topology() try: destroy_simple_topology(topology) LOG.debug("MDTS ready to run tests.") return except Exception: destroy_simple_topology(topology) current_attempts += 1 LOG.debug("MDTS failed to bind port... check again. Attempt: %d" % current_attempts) raise RuntimeError("MDTS was unable to bind a single port... Exiting.")
def restart_midolman_agents(): agents = service.get_all_containers('midolman') for agent in agents: agent.restart(wait=True)
def afterTest(self, test): """Inserts merker to the MM logs""" marker = self._get_markers_for_test(test.id())['end'] midolman_hosts = service.get_all_containers('midolman') for midolman in midolman_hosts: midolman.set_log_marker(marker)
def build(self): """ Build physical topology from the data. Args: filename: filename that defines physical topology data: python dictionary object to represent the physical topology """ LOG.debug('-' * 80) LOG.debug("build") LOG.debug('-' * 80) #for b in self._bridges: # bridge = b['bridge'] # # TODO(tomohiko) Need to something when not bridge['provided']? # if bridge['provided']: # LOG.info('Skipped building bridge=%r', bridge) hosts = service.get_all_containers('midolman') midonet_api_host = service.get_container('midonet-api') midonet_api = midonet_api_host.get_midonet_api() if is_vxlan_enabled(): tz = midonet_api.add_vxlan_tunnel_zone() else: tz = midonet_api.add_gre_tunnel_zone() tz.name('mdts-test') tz.create() for host in hosts: tz_host = tz.add_tunnel_zone_host() tz_host.ip_address(host.get_ip_address()) tz_host.host_id(host.get_midonet_host_id()) tz_host.create() # for h in self._hosts: # host = h['host'] # host_container = service.load_from_name('midonet-agent.'+host['id']) # if host.get('tunnel_zone'): # tz_data = host.get('tunnel_zone') # tzs = self._api.get_tunnel_zones() # # # Ensure that TZ exists # tz = [t for t in tzs if t.get_name() == tz_data['name']] # if tz == []: # if is_vxlan_enabled(): # tz = self._api.add_vxlan_tunnel_zone() # else: # tz = self._api.add_gre_tunnel_zone() # tz.name(tz_data['name']) # tz.create() # else: # tz = tz[0] # # # Ensure that the host is in the TZ # tz_hosts = tz.get_hosts() # tz_host = filter( # lambda x: x.get_host_id() == host['mn_host_id'], # tz_hosts) # if tz_host == []: # tz_host = tz.add_tunnel_zone_host() # tz_host.ip_address(tz_data['ip_addr']) # tz_host.host_id(host['mn_host_id']) # tz_host.create() #if host['provided'] == True: # LOG.info('Skipped building host=%r', host) #else: # #TODO(tomoe): when we support provisioning Midolman host with # # this tool. # pass #interfaces = host['interfaces'] #futures = [] #for i in interfaces: # iface = Interface(i['interface'], host) # self._interfaces[(host['id'], i['interface']['id'])] = iface # f = iface.create() # futures.append(f) #wait_on_futures(futures) LOG.debug('-' * 80) LOG.debug("end build") LOG.debug('-' * 80)
def _add_hosts_to_tunnel_zone(self): _tzone_name = self._ptm.get_default_tunnel_zone_name() agents = service.get_all_containers('midolman') for agent in agents: self._ptm.add_host_to_tunnel_zone(agent.get_hostname(), _tzone_name)
def stop_midolman_agents(): agents = service.get_all_containers('midolman') for agent in agents: agent.stop(wait=True)
def _add_hosts_to_tunnel_zone(self): _tzone_name = self._ptm.get_default_tunnel_zone_name() agents = service.get_all_containers('midolman') for agent in agents: self._ptm.add_host_to_tunnel_zone( agent.get_hostname(), _tzone_name)
def stop_midolman_agents(): agents = service.get_all_containers('midolman') for agent in agents: agent.stop(wait=True)
def restart_midolman_agents(): agents = service.get_all_containers('midolman') for agent in agents: agent.restart(wait=True)