beef up the AI/ML framework tests by adding InfluxDB as data source and populate...
[it/test.git] / XTesting / powder-control / run_profile_example.py
1 #!/usr/bin/env python3
2 import logging
3 import mmap
4 import multiprocessing as mp
5 import powder.experiment as pexp
6 import random
7 import re
8 import string
9 import sys
10 import time
11 from powder.profile import PowderProfile
12
13 class RunTest:
14     """Based on the return values from the process that starts a given POWDER profile,
15     create ssh connection and run desired commands, e.g., test steps that's already
16     published as scripts or pure commands
17
18     """
19
20     TEST_SUCCEEDED   = 0  # all steps succeeded
21     TEST_FAILED      = 1  # one of the steps failed
22     TEST_NOT_STARTED = 2  # could not instantiate an experiment to run the test on
23
24     def run(self):
25         powder_host = PowderProfile()
26         # expect the start on a specified profile succeeds and return
27         # an IPv4 address to proceed to the next step
28         status, ip_address = powder_host.run()
29
30         if not ip_address:
31             sys.exit(self.TEST_NOT_STARTED)
32         elif self._start_powder_experiment(ip_address):
33             sys.exit(self.TEST_FAILED)
34         else:    
35             sys.exit(self.TEST_SUCCEEDED)
36
37     def _start_powder_experiment(self, ip_address):
38         logging.info('Executing ssh commands on host:{}'.format(ip_address))
39         node = pexp.Node(ip_address=ip_address)
40         ssh_node = node.ssh.open()
41         # the example commands shown below are to set up the AI/ML FW from scratch
42         ssh_node.command('sudo groupadd docker && sudo usermod -aG docker osc_int')
43         ssh_node.close(5)
44         ssh_node = node.ssh.open()
45         ssh_node.command('git clone https://gerrit.o-ran-sc.org/r/aiml-fw/aimlfw-dep')
46         ssh_node.command('cd aimlfw-dep && bin/install_traininghost.sh 2>&1 | tee /tmp/install.log', timeout=1800)
47         ssh_node.close(5)
48
49 if __name__ == '__main__':
50     powdertest = RunTest()
51     powdertest.run()