fix pip_install
[tests.git] / system / TestPlc.py
index b6f211f..b6f7e0e 100644 (file)
@@ -153,7 +153,7 @@ class TestPlc:
     default_steps = [
         'show', SEP,
         'plcvm_delete','plcvm_timestamp','plcvm_create', SEP,
-        'plc_install', 'plc_configure', 'plc_start', SEP,
+        'django_install', 'plc_install', 'plc_configure', 'plc_start', SEP,
         'keys_fetch', 'keys_store', 'keys_clear_known_hosts', SEP,
         'plcapi_urls','speed_up_slices', SEP,
         'initscripts', 'sites', 'nodes', 'slices', 'nodegroups', 'leases', SEP,
@@ -177,7 +177,7 @@ class TestPlc:
         # but as the stress test might take a while, we sometimes missed the debug mode..
         'probe_kvm_iptables',
         'ping_node', 'ssh_node_debug', 'plcsh_stress_test@1', SEP,
-        'ssh_node_boot', 'node_bmlogs', 'ssh_slice', 'ssh_slice_basics', 'check_initscripts', SEP,
+        'ssh_node_boot', 'node_bmlogs', 'ssh_slice', 'ssh_slice_basics', SEP,
         'ssh_slice_sfa@1', SEPSFA,
         'sfa_rspec_empty@1', 'sfa_allocate_empty@1', 'sfa_provision_empty@1','sfa_check_slice_plc_empty@1', SEPSFA,
         'sfa_delete_slice@1', 'sfa_delete_user@1', SEPSFA,
@@ -207,7 +207,7 @@ class TestPlc:
         'sfa_get_expires', SEPSFA,
         'plc_db_dump' , 'plc_db_restore', SEP,
         'check_netflow','check_drl', SEP,
-        'slice_fs_present', SEP,
+        'slice_fs_present', 'check_initscripts', SEP,
         'standby_1_through_20','yes','no',SEP,
         'install_syslinux6', 'bonding_builds', 'bonding_nodes', SEP,
         ]
@@ -350,6 +350,9 @@ class TestPlc:
         self.run_in_guest("yum-complete-transaction -y")
         return self.yum_check_installed(rpms)
 
+    def pip_install(self, package):
+        return self.run_in_guest("pip -y install {}".format(package)) == 0
+
     def auth_root(self):
         return {'Username'   : self.plc_spec['settings']['PLC_ROOT_USER'],
                 'AuthMethod' : 'password',
@@ -661,8 +664,8 @@ class TestPlc:
         "vserver delete the test myplc"
         stamp_path = self.vm_timestamp_path()
         self.run_in_host("rm -f {}".format(stamp_path))
-        self.run_in_host("virsh -c lxc:// destroy {}".format(self.vservername))
-        self.run_in_host("virsh -c lxc:// undefine {}".format(self.vservername))
+        self.run_in_host("virsh -c lxc:/// destroy {}".format(self.vservername))
+        self.run_in_host("virsh -c lxc:/// undefine {}".format(self.vservername))
         self.run_in_host("rm -fr /vservers/{}".format(self.vservername))
         return True
 
@@ -711,6 +714,15 @@ class TestPlc:
         create_vserver="{build_dir}/{script} {script_options} {vserver_name}".format(**locals())
         return self.run_in_host(create_vserver) == 0
 
+    ### install django through pip
+    def django_install(self):
+        # plcapi requires Django, that is no longer provided py fedora as an rpm
+        # so we use pip instead
+        """
+        pip install Django
+        """
+        return self.pip_install('Django')
+
     ### install_rpm
     def plc_install(self):
         """
@@ -785,41 +797,18 @@ class TestPlc:
         utils.system('rm {}'.format(tmpname))
         return True
 
-# f14 is a bit odd in this respect, although this worked fine in guests up to f18
-# however using a vplc guest under f20 requires this trick
-# the symptom is this: service plc start
-# Starting plc (via systemctl):  Failed to get D-Bus connection: \
-#    Failed to connect to socket /org/freedesktop/systemd1/private: Connection refused
-# weird thing is the doc says f14 uses upstart by default and not systemd
-# so this sounds kind of harmless
-    def start_service(self, service):
-        return self.start_stop_service(service, 'start')
-    def stop_service(self, service):
-        return self.start_stop_service(service, 'stop')
-
-    def start_stop_service(self, service, start_or_stop):
-        "utility to start/stop a service with the special trick starting with f14"
-        has_systemctl = False
-        if self.options.fcdistro[0] == 'f':
-            number = int(self.options.fcdistro[1:])
-            if number >= 14:
-                has_systemctl = True
-        if not has_systemctl:
-            return self.run_in_guest("service {} {}".format(service, start_or_stop)) == 0
-        else:
-            # patch /sbin/service so it does not reset environment
-            self.run_in_guest('sed -i -e \\"s,env -i,env,\\" /sbin/service')
-            # this is because our own scripts in turn call service
-            return self.run_in_guest("SYSTEMCTL_SKIP_REDIRECT=true service {} {}"\
-                                     .format(service, start_or_stop)) == 0
+    # care only about f>=27
+    def start_stop_systemd(self, service, start_or_stop):
+        "utility to start/stop a systemd-defined service (sfa)"
+        return self.run_in_guest("systemctl {} {}".format(start_or_stop, service)) == 0
 
     def plc_start(self):
-        "service plc start"
-        return self.start_service('plc')
+        "start plc through systemclt"
+        return self.start_stop_systemd('plc', 'start')
 
     def plc_stop(self):
-        "service plc stop"
-        return self.stop_service('plc')
+        "stop plc through systemctl"
+        return self.start_stop_systemd('plc', 'stop')
 
     def plcvm_start(self):
         "start the PLC vserver"
@@ -1456,7 +1445,8 @@ class TestPlc:
             # the issue here is that we have the server run in background
             # and so we have no clue if it took off properly or not
             # looks like in some cases it does not
-            if not spec['s_sliver'].run_tcp_server(port, timeout=20):
+            address = spec['s_sliver'].test_node.name()
+            if not spec['s_sliver'].run_tcp_server(address, port, timeout=20):
                 overall = False
                 break
 
@@ -1519,7 +1509,9 @@ class TestPlc:
 
     def sfa_install_all(self):
         "yum install sfa sfa-plc sfa-sfatables sfa-client"
-        return self.yum_install("sfa sfa-plc sfa-sfatables sfa-client")
+        return (self.yum_install("sfa sfa-plc sfa-sfatables sfa-client") and
+                self.run_in_guest("systemctl enable sfa-registry")==0 and
+                self.run_in_guest("systemctl enable sfa-aggregate")==0)
 
     def sfa_install_core(self):
         "yum install sfa"
@@ -1707,8 +1699,9 @@ class TestPlc:
         return self.run_in_guest('sfaadmin reg import_registry') == 0
 
     def sfa_start(self):
-        "service sfa start"
-        return self.start_service('sfa')
+        "start SFA through systemctl"
+        return (self.start_stop_systemd('sfa-registry', 'start') and
+                self.start_stop_systemd('sfa-aggregate', 'start'))
 
 
     def sfi_configure(self):
@@ -1804,8 +1797,9 @@ class TestPlc:
     def sfa_delete_slice(self): pass
 
     def sfa_stop(self):
-        "service sfa stop"
-        return self.stop_service('sfa')
+        "stop sfa through systemclt"
+        return (self.start_stop_systemd('sfa-aggregate', 'stop') and
+                self.start_stop_systemd('sfa-registry', 'stop'))
 
     def populate(self):
         "creates random entries in the PLCAPI"
@@ -1929,14 +1923,13 @@ class TestPlc:
     def plc_db_restore(self):
         'restore the planetlab5 DB - looks broken, but run -n might help'
         dump = self.dbfile("planetab5")
-        ##stop httpd service
-        self.run_in_guest('service httpd stop')
+        self.run_in_guest('systemctl stop httpd')
         # xxx - need another wrapper
         self.run_in_guest_piped('echo drop database planetlab5', 'psql --user=pgsqluser template1')
         self.run_in_guest('createdb -U postgres --encoding=UNICODE --owner=pgsqluser planetlab5')
         self.run_in_guest('psql -U pgsqluser planetlab5 -f ' + dump)
         ##starting httpd service
-        self.run_in_guest('service httpd start')
+        self.run_in_guest('systemctl start httpd')
 
         utils.header('Database restored from ' + dump)