def setup_class(cls, with_ha=False): """ This method is called once when the class is first instanciated. It sets up the testing conditions, while saving the current configuration. """ Test.setup_class() cls.test_path = cls.results_path+cls.date+"/TestConfig/" if not isdir(cls.test_path): makedirs(cls.test_path) cls.with_ha = with_ha cls.local_ha_state = cls.client.call("ha", "getState")[0] if cls.local_ha_state != "CONNECTED" and with_ha: test.skip("!! Are you mad ? You're trying to do a HA test without being actually connected (local state is %s) !!" % cls.local_ha_state) if with_ha: cls.remote_client = cls.createClient(cust_host="5.0.0.2") # Check HA states locally and remotly cls.remote_ha_state = cls.remote_client.call("ha", "getState")[0] if cls.remote_ha_state != "CONNECTED": test.skip("!! Are you mad ? You're trying to do a HA test without being actually connected (remote state is %s) !!" % cls.remote_ha_state) cls.ssh_client = cls.createSSHClient(host="5.0.0.2")
def setup_class(cls): """ This method is called once when the class is first instanciated. It sets up the testing conditions, while saving the current configuration. """ Test.setup_class() cls.test_path = cls.results_path+cls.date+"/TestBonding/" if not isdir(cls.test_path): makedirs(cls.test_path) # Get /etc/network/interfaces md5sum for comparison cls.firstMD5_interfaces = cls.md5sum("/etc/network/interfaces") # Get and save our netconfig netconfig = cls.client.call("network","getNetconfig") cls.orig = deepcopy(netconfig) netcfg = deserialize(netconfig) # Let's configure for our test eth1 = netcfg.getInterfaceBySystemName('eth1') eth2 = netcfg.getInterfaceBySystemName('eth2') netcfg_bondings = set(netcfg.bondings) for bonding in netcfg_bondings: if eth1 in bonding.ethernets: netcfg.removeInterface(bonding) break netcfg.removeInterface(eth1) netcfg_bondings = set(netcfg.bondings) for bonding in netcfg_bondings: if eth2 in bonding.ethernets: netcfg.removeInterface(bonding) break netcfg.removeInterface(eth2) bond0 = netcfg.createBonding('bond0', set((eth1, eth2))) # Give an IPv4 configuration to our bonding net = NetRW( "James", IP("192.168.242.0/24"), service_ip_addrs=set(IP("192.168.242.1"),) ) bond0.addNet(net) serialized = netcfg.serialize() # Let's apply the new configuration cls.takeNuconfWriteRole() cls.client.call("network", "setNetconfig", serialized, "created a bonding") cls.apply_nuconf() # Fetch the system name of the bonding we've just created netconfig = cls.client.call("network", "getNetconfig") netcfg = deserialize(netconfig) bond_interface = netcfg.getInterfaceByUserLabel('bond0') cls.bond_sys_name = bond_interface.getSystem_name()
def teardown_class(cls): """ This method is called once when all tests have been done. It restores the saved configuration. """ # If the ruleset used exists, we delete it for ruleset in cls.client.call('ufwi_ruleset', 'rulesetList', 'ruleset'): if cls.ruleV4['name'] in ruleset: cls.client.call('ufwi_ruleset', 'rulesetDelete', 'ruleset', cls.ruleV4['name']) break # If there was any ruleset open, now we close it try: cls.client.call('ufwi_ruleset', 'rulesetClose') except RpcdError: pass # If the previous ruleset still exists, we restore it if cls.origRuleset: for ruleset in cls.client.call('ufwi_ruleset', 'rulesetList', 'ruleset'): if 'origRuleset' in ruleset: cls.client.call('ufwi_ruleset', 'rulesetOpen', 'ruleset', cls.origRuleset) cls.client.call('ufwi_ruleset', 'applyRules', 'True', 'True') cls.client.call('ufwi_ruleset', 'rulesetClose') break # Retour a la configuration initiale cls.client.call('network', 'setNetconfig', cls.orig, 'pas de message') cls.apply_ufwi_conf() Test.teardown_class()
def setup_class(cls): """ This method is called once when the class is first instanciated. It sets up the testing conditions, while saving the current configuration. """ Test.setup_class() cls.test_path = cls.results_path+cls.date+"/TestNetwork/" if not isdir(cls.test_path): makedirs(cls.test_path) with open("/sys/class/net/eth0/operstate","r") as handle: eth0_state = handle.readlines() cls.firstMD5_interfaces = cls.md5sum("/etc/network/interfaces") serialized = cls.client.call('network','getNetconfig') cls.orig = deepcopy(serialized) # Configure the network according to the input script serialized = cls.configure_network(serialized) # Save and apply the configuration cls.takeNuconfWriteRole() cls.client.call("network", "setNetconfig", serialized, "none") cls.apply_nuconf() # Let's check that eth0 isn't affected by our changes with open("/sys/class/net/eth0/operstate","r") as handle: state = handle.readlines() assert eth0_state == state, "eth0 changes when it shouldn't"
def teardown_class(cls): """ This method is called once when all tests have been done. It restores the saved configuration. """ if cls.with_ha: cls.ssh_client.close() Test.teardown_class()
def setup_class(cls): """ This method is called once when the class is first instanciated. It sets up the testing conditions, while saving the current configuration. """ Test.setup_class() cls.test_path = cls.results_path+cls.date+"/TestDHCP/" if not isdir(cls.test_path): makedirs(cls.test_path) # Configure the network according to the input script serialized = cls.client.call('network', 'getNetconfig') cls.net_orig = deepcopy(serialized) iface = (cls.test_network["iface"],) (serialized, net) = cls.configure_network(serialized, iface, cls.test_network) # Save the original configuration orig = cls.client.call('dhcp', 'getDhcpConfig') cls.dhcp_orig = deepcopy(orig) # Prepare to change the configuration netcfg = deserialize_net(serialized) dhcpcfg = deserialize_dhcp(orig, netcfg) # Do we configure the DNS server ? dns_server = None if cls.configure_dns: dns_server = IP(cls.test_dhcp['dns_server']) # Do we configure the router ? router = None if cls.configure_router: router = IP(cls.test_dhcp['router']) dhcp_range = DHCPRange( router, dns_server, IP(cls.test_dhcp['start']), IP(cls.test_dhcp['end']), net ) assert dhcp_range.isValid() dhcpcfg.ranges.add(dhcp_range) dhcpcfg.enabled = True # Save and apply the configuration cls.takeNuconfWriteRole() cls.client.call("network", "setNetconfig", netcfg.serialize(), "Add a network for dhcp testing purposes") cls.client.call("dhcp", "setDhcpConfig", dhcpcfg.serialize(), "Add a dhcp range for testing purposes") cls.apply_nuconf()
def teardown_class(cls): """ This method is called once when all tests have been done. It restores the saved configuration. """ cls.client.call('network', 'setNetconfig', cls.orig, 'pas de message') cls.apply_nuconf() Test.teardown_class()
def teardown_class(cls): """ This method is called once when all tests have been done. It restores the saved configuration. """ # Retour a la configuration initiale cls.client.call("network", "setNetconfig", cls.orig, "pas de message") cls.apply_nuconf() Test.teardown_class()
def setup_class(cls): """ This method is called once when the class is first instanciated. It sets up the testing conditions, while saving the current configuration. """ Test.setup_class() cls.test_path = cls.results_path+cls.date+"/TestAccess/" if not isdir(cls.test_path): makedirs(cls.test_path)
def setup_class(cls): """ This method is called once when the class is first instanciated. It sets up the testing conditions, while saving the current configuration. """ Test.setup_class() cls.test_path = cls.results_path+cls.date+"/TestBondingVlan/" if not isdir(cls.test_path): makedirs(cls.test_path) # Get and save our netconfig netconfig = cls.client.call("network","getNetconfig") cls.orig = deepcopy(netconfig) netcfg = deserialize(netconfig) # Let's configure for our test cls.eth1 = netcfg.getInterfaceBySystemName('eth1') netcfg_bondings = set(netcfg.bondings) for bonding in netcfg_bondings: if cls.eth1 in bonding.ethernets: netcfg.removeInterface(bonding) break netcfg.removeInterface(cls.eth1) # Let's add a few vlans cls.vlans = [] for id in range(1,2): myvlan = netcfg.createVlan(cls.eth1, "vlan%s" % id, id) net = NetRW( "my_net%s" % id, IP("192.168.10%s.0/24" % id), service_ip_addrs=set(IP("192.168.10%s.1" % id),) ) myvlan.addNet(net) my_syst_name = myvlan.getSystem_name() cls.vlans.append(my_syst_name) # We're gonna reuse this config in our tests cls.test_netcfg = netcfg # Let's apply the new configuration serialized = netcfg.serialize() cls.takeNuconfWriteRole() cls.client.call("network", "setNetconfig", serialized, "added 2 vlans") cls.apply_nuconf() # Fetch the system name of the bonding we've just created netconfig = cls.client.call("network", "getNetconfig") netcfg = deserialize(netconfig)
def teardown_class(cls): """ This method is called once when all tests have been done. It restores the saved configuration. """ # Clean after our tests cls.takeNuconfWriteRole() cls.client.call('openvpn', 'setOpenVpnConfig', cls.orig, 'test openvpn - restore orginal configuration') cls.apply_nuconf() cls.client.call('nupki', 'deletePKI', cls.PKI_TEST['name']) Test.teardown_class()
def teardown_class(cls): """ This method is called once when all tests have been done. It restores the saved configuration. """ # Here, unlike other test classes, we won't restore the old # configuration for at least 2 reasons : # 1. The original user directory configuration may be invalid (like in # a fresh install) # 2. The original user directory configuration may be an Active # Directory one, and these take a loooooooooooong time to join. #cls.client.call('nuauth','setNuauthConfig',cls.orig,'pas de message') #cls.client.call('config','apply') cls.client.call('hostname', 'setShortHostname', cls.old_hostname, 'teardown : hostname') cls.apply_nuconf() Test.teardown_class()
def teardown_class(cls): """ This method is called once when all tests have been done. It restores the saved configuration. """ with open("/sys/class/net/eth0/operstate","r") as handle: eth0_state = handle.readlines() cls.client.call('network', 'setNetconfig', cls.orig, 'pas de message') cls.apply_nuconf() # Let's check that eth0 isn't affected by our changes with open("/sys/class/net/eth0/operstate","r") as handle: state = handle.readlines() assert eth0_state == state, "eth0 changes when it shouldn't" Test.teardown_class()
def teardown_class(cls): """ This method is called once when all tests have been done. It restores the saved configuration. """ # Clean after our tests cls.client.call('network', 'setNetconfig', cls.net_orig, 'pas de message') cls.client.call('dhcp', 'setDhcpConfig', cls.dhcp_orig, "Add a dhcp range for testing purposes") cls.apply_nuconf() Test.teardown_class()
def setup_class(cls): """ This method is called once when the class is first instanciated. It sets up the testing conditions, while saving the current configuration. """ Test.setup_class() cls.old_hostname = cls.client.call('hostname', 'getShortHostname') cls.test_path = cls.results_path+cls.date+"/"+cls.__name__+"/" if not isdir(cls.test_path): makedirs(cls.test_path) # Let's create a backup of the original configuration cls.orig = cls.client.call('nuauth','getNuauthConfig') # We get some md5 sums to check if it the files are written cls.firstMD5_nsswitch_conf = cls.md5sum("/etc/nsswitch.conf") cls.firstMD5_libnss_ldap = cls.md5sum("/etc/libnss-ldap.conf") cls.firstMD5_ldap_conf = cls.md5sum("/etc/ldap/ldap.conf") ########################################################### cls.takeNuconfWriteRole() # ***APPLY*** and synchronize cls.configureNtpApplySynchronize() cls.configureHostname() cls.configureDns() # We create a new Nuauth (user dir) configuration nuauthcfg = NuauthCfg(cls.authConf, cls.orgConf) serialized = nuauthcfg.serialize() # We apply this configuration cls.client.call('nuauth', 'setNuauthConfig', serialized, 'tests') cls.configureKeytab() cls.apply_nuconf() # We get some md5 sums to check if it the files are written cls.secondMD5_nsswitch_conf = cls.md5sum("/etc/nsswitch.conf") cls.secondMD5_libnss_ldap = cls.md5sum("/etc/libnss-ldap.conf") cls.secondMD5_ldap_conf = cls.md5sum("/etc/ldap/ldap.conf")
def setup_class(cls): """ This method is called once when the class is first instanciated. It sets up the testing conditions, while saving the current configuration. """ Test.setup_class() cls.test_path = cls.results_path + cls.date + "/" + cls.__name__ + "/" if not isdir(cls.test_path): makedirs(cls.test_path) # We save the configuration to restore it later serialized = cls.client.call("network", "getNetconfig") cls.orig = deepcopy(serialized) for i in serialized["ethernets"]: # Remove every route if serialized["ethernets"][i]["routes"] != {}: serialized["ethernets"][i]["routes"] = {} netcfg = deserialize(serialized) eth1 = netcfg.getInterfaceBySystemName("eth1") netcfg_bondings = set(netcfg.bondings) for bonding in netcfg_bondings: if eth1 in bonding.ethernets: netcfg.removeInterface(bonding) break netcfg.removeInterface(eth1) net = NetRW("Test", IP(cls.network_test["local_net"]), service_ip_addrs=set(IP(cls.network_test["local_ip"]))) eth1.addNet(net) my_route = RouteRW(IP(cls.network_test["routed_net"]), IP(cls.network_test["gateway"])) eth1.addRoute(my_route) # In order to check that /etc/network/interfaces does change : cls.firstMD5_interfaces = cls.md5sum("/etc/network/interfaces") # We apply the network configuration serialized = netcfg.serialize() cls.takeNuconfWriteRole() cls.client.call("network", "setNetconfig", serialized, "pas de message") cls.apply_nuconf()
def teardown_class(cls): """ This method is called once when all tests have been done. It restores the saved configuration. """ cls.client.call('network','setNetconfig',cls.orig,'pas de message') cls.client.call('config','apply') cls.client.logout() # Let's check that eth0 isn't affected by our changes a = 0 while a < 200: with open("/sys/class/net/eth0/operstate","r") as fd: state = fd.readlines() assert "up\n" in state, "eth0 changes when it shouldn't" sleep(0.2) a+=1 Test.cleanMyDir(cls.test_path) Test.teardown_class()
def setup_class(cls): """ This method is called once when the class is first instanciated. It sets up the testing conditions, while saving the current configuration. """ Test.setup_class() # Save the original configuration cls.orig = cls.client.call('openvpn', 'getOpenVpnConfig') conf = OpenVpnConf.deserialize(cls.orig) is_valid, error = conf.isValidWithMsg() assert is_valid, "original configuration is invalid ('%s : %s') !" % (error, cls.orig) # Create a pki cls.client.call('nupki', 'createPKI', cls.PKI_TEST["name"], cls.PKI_TEST["org unit"], cls.PKI_TEST["org"], cls.PKI_TEST["loc"], cls.PKI_TEST["state"], cls.PKI_TEST["country"], 1826) cls.client.call('nupki', 'createCertificate', cls.CERT_TEST)
def setup_class(cls): """ This method is called once when the class is first instanciated. It sets up the testing conditions, while saving the current configuration. """ Test.setup_class() cls.test_path = cls.results_path+cls.date+"/TestDNS/" if not isdir(cls.test_path): makedirs(cls.test_path) cls.firstMD5_resolv_conf = cls.md5sum("/etc/bind/named.conf.options") resolv_config = cls.client.call('resolv', 'getResolvConfig') cls.orig = deepcopy(resolv_config) # Test DNS resolv_config['nameserver1'] = cls.DNS_server['ip'] resolv_config['nameserver2'] = '' # Apply configuration cls.takeNuconfWriteRole() print datetime.now(), "applying dumbconfig" dumbconfig = {'domain': 'foobar.com', 'nameserver1': '192.168.254.253', 'nameserver2': '192.168.254.254'} cls.client.call('resolv', 'setResolvConfig', dumbconfig, 'resolv dumbconfig') cls.apply_nuconf() print datetime.now(), "applied dumbconfig" print datetime.now(), "applying testconfig" cls.client.call('resolv', 'setResolvConfig', resolv_config, 'pas de message') cls.apply_nuconf() print datetime.now(), "applied testconfig"
def setup_class(cls): """ This method is called once when the class is first instanciated. It sets up the testing conditions, while saving the current configuration. """ Test.setup_class() cls.test_path = cls.results_path+cls.date+"/"+cls.__name__+"/" if not isdir(cls.test_path): makedirs(cls.test_path) # We save the configuration to restore it later serialized = cls.client.call('network', 'getNetconfig') cls.orig = deepcopy(serialized) # Let's tune the netconf to match our needs netcfg = deserialize(serialized) eth1 = netcfg.getInterfaceBySystemName('eth1') eth2 = netcfg.getInterfaceBySystemName('eth2') netcfg_bondings = set(netcfg.bondings) for bonding in netcfg_bondings: if eth1 in bonding.ethernets: netcfg.removeInterface(bonding) break netcfg.removeInterface(eth1) netcfg_bondings = set(netcfg.bondings) for bonding in netcfg_bondings: if eth2 in bonding.ethernets: netcfg.removeInterface(bonding) break netcfg.removeInterface(eth2) net1 = NetRW( "Test1", IP("192.168.16.0/24"), service_ip_addrs=set(IP("192.168.16.1")) ) net2 = NetRW( "Test2", IP("192.168.17.0/24"), service_ip_addrs=set(IP("192.168.17.1")) ) eth1.addNet(net1) eth2.addNet(net2) serialized = netcfg.serialize() cls.takeNuconfWriteRole() cls.client.call("network", "setNetconfig", serialized, "none") cls.apply_ufwi_conf() cls.should_have_resources = '<interface id=\"eth1\" name=\"eth1\">\n' \ ' <network address=\"192.168.16.0/24\" id=\"Test1\" />\n' \ ' </interface>\n' \ ' <interface id=\"eth2\" name=\"eth2\">\n' \ ' <network address=\"192.168.17.0/24\" id=\"Test2\" />\n' \ ' </interface>' # We save the last applied ruleset name cls.origRuleset = None production_rules = cls.client.call('ufwi_ruleset', 'productionRules') if production_rules.has_key('ruleset'): cls.origRuleset = cls.client.call('ufwi_ruleset', 'productionRules')['ruleset'] # If the ruleset used exists, we delete it for ruleset in cls.client.call('ufwi_ruleset', 'rulesetList', 'ruleset'): if cls.ruleV4['name'] in ruleset: cls.client.call('ufwi_ruleset', 'rulesetDelete', 'ruleset',cls.ruleV4['name']) break # We create a new ruleset and name it cls.client.call('ufwi_ruleset', 'rulesetCreate', 'ruleset', '') # We create a user group user_group = {'group': '9000', 'id': 'tests'} cls.client.call('ufwi_ruleset', 'objectCreate', 'user_groups', user_group, False) # We add the rule cls.client.call('ufwi_ruleset', 'ruleCreate', 'acls-ipv4', cls.ruleV4['rule']) # Save and apply the rule cls.client.call('ufwi_ruleset', 'rulesetSaveAs', cls.ruleV4['name']) cls.client.call('ufwi_ruleset', 'applyRules', 'True', 'True') cls.client.call('ufwi_ruleset', 'rulesetClose')
def teardown_class(cls): """ This method is called once when all tests have been done. It restores the saved configuration. """ Test.teardown_class()
def setup_class(cls): Test.setup_class() cls.test_path = cls.results_path+cls.date+"/TestHA/" if not isdir(cls.test_path): makedirs(cls.test_path) #################################### Configuration of the secondary # Check that the EW has a license cls.checkAndUploadLicense(Test.cluster_ha["secondary"]) # Connect to the other nucentral cls.other_client = cls.createClient(host=Test.cluster_ha["secondary"]) # Let's synchronize our watches cls.client.call('ntp', 'setNtpConfig', { 'ntpservers': u'172.16.0.1', 'isFrozen': False }, u'message') cls.client.call('ntp', 'syncTime') # Let's configure the HA on the secondary cls.other_client.call('ha', 'configureHA', cls.secondary_ha_configuration, u'message') cls.other_client.call('config','apply') cls.other_client.logout() ################################################################### ###################################### Configuration of the primary # Check that the EW has a license cls.checkAndUploadLicense(Test.cluster_ha["secondary"]) # Connect to the localhost nucentral cls.client = cls.createClient() # We apply an configuration prior the HA configuration & join to # see if it will be replicated for call in cls.prior_configuration: cls.client.call(*call) # Save original configuration serialized = cls.client.call('network','getNetconfig') cls.orig=deepcopy(serialized) netcfg = deserialize(serialized) # Let's synchronize our watches cls.client.call('ntp', 'setNtpConfig', { 'ntpservers': u'172.16.0.1', 'isFrozen': False }, u'message') cls.client.call('ntp', 'syncTime') # Configure the network according to the input script serialized = cls.configure_network(serialized) # Configure the HA on the primary cls.client.call('ha', 'configureHA', cls.primary_ha_configuration, u'message') cls.client.call("network","setNetconfig",serialized, "none") cls.client.call("config","apply") ################################################################### ############################################################## Join # Fetch and save some of the configurations for comparison purposes cls.config=deepcopy(cls.client.call("config","get"))