Support for xtesting
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / rapid / rapid_machine.py
index b89c038..8466c85 100644 (file)
@@ -24,7 +24,7 @@ class RapidMachine(object):
     """
     Class to deal with a PROX instance (VM, bare metal, container)
     """
-    def __init__(self, key, user, vim, rundir, machine_params):
+    def __init__(self, key, user, vim, rundir, machine_params, configonly):
         self.name = machine_params['name']
         self.ip = machine_params['admin_ip']
         self.key = key
@@ -32,6 +32,7 @@ class RapidMachine(object):
         self.rundir = rundir
         self.dp_ports = []
         self.dpdk_port_index = []
+        self.configonly = configonly
         index = 1
         while True:
             ip_key = 'dp_ip{}'.format(index)
@@ -45,15 +46,11 @@ class RapidMachine(object):
                 break
         self.rundir = rundir
         self.machine_params = machine_params
-        self._client = prox_ctrl(self.ip, self.key, self.user)
-        self._client.connect()
-        if vim in ['OpenStack']:
-            self.devbind()
-        self.generate_lua(vim)
-        self._client.scp_put(self.machine_params['config_file'], '{}/{}'.format(self.rundir, machine_params['config_file']))
+        self.vim = vim
 
     def __del__(self):
-        self._client.scp_get('/prox.log', './{}.prox.log'.format(self.name))
+        if ((not self.configonly) and self.machine_params['prox_socket']):
+            self._client.scp_get('/prox.log', './{}.prox.log'.format(self.name))
 
     def get_cores(self):
         return (self.machine_params['cores'])
@@ -66,8 +63,9 @@ class RapidMachine(object):
             cmd =  'sed -i \'s/MACADDRESS/' + dp_port['mac'] + '/\' ' + DevBindFileName 
             result = self._client.run_cmd(cmd)
             RapidLog.debug('devbind.sh MAC updated for port {} on {} {}'.format(index, self.name, result))
-            result = self._client.run_cmd(DevBindFileName)
-            RapidLog.debug('devbind.sh running for port {} on {} {}'.format(index, self.name, result))
+            if ((not self.configonly) and self.machine_params['prox_launch_exit']):
+                result = self._client.run_cmd(DevBindFileName)
+                RapidLog.debug('devbind.sh running for port {} on {} {}'.format(index, self.name, result))
 
     def generate_lua(self, vim, appendix = ''):
         PROXConfigfile =  open (self.machine_params['config_file'], 'r')
@@ -99,11 +97,27 @@ class RapidMachine(object):
         self._client.scp_put('helper.lua', self.rundir + '/helper.lua')
 
     def start_prox(self, autostart=''):
-        if self.machine_params['prox_launch_exit']:
-            cmd = 'sudo {}/prox {} -t -o cli -f {}/{}'.format(self.rundir, autostart, self.rundir, self.machine_params['config_file'])
-            result = self._client.fork_cmd(cmd, 'PROX Testing on {}'.format(self.name))
-            RapidLog.debug("Starting PROX on {}: {}, {}".format(self.name, cmd, result))
-        self.socket = self._client.connect_socket()
+        if self.machine_params['prox_socket']:
+            self._client = prox_ctrl(self.ip, self.key, self.user)
+            self._client.connect()
+            if self.vim in ['OpenStack']:
+                self.devbind()
+            self.generate_lua(self.vim)
+            self._client.scp_put(self.machine_params['config_file'], '{}/{}'.format(self.rundir, self.machine_params['config_file']))
+            if ((not self.configonly) and self.machine_params['prox_launch_exit']):
+                cmd = 'sudo {}/prox {} -t -o cli -f {}/{}'.format(self.rundir, autostart, self.rundir, self.machine_params['config_file'])
+                RapidLog.debug("Starting PROX on {}: {}".format(self.name, cmd))
+                result = self._client.run_cmd(cmd, 'PROX Testing on {}'.format(self.name))
+                #RapidLog.debug("Finished PROX on {}: {}, {}".format(self.name, cmd, result))
+                RapidLog.debug("Finished PROX on {}: {}".format(self.name, cmd))
+
+    def close_prox(self):
+        if (not self.configonly) and self.machine_params['prox_socket'] and self.machine_params['prox_launch_exit']:
+            self.socket.quit()
+
+    def connect_prox(self):
+        if self.machine_params['prox_socket']:
+           self.socket = self._client.connect_socket()
 
     def start(self):
         self.socket.start(self.get_cores())