def __install(self): version = os.environ.get('VERSION', '') if version.startswith('v'): version = version[1:] assert version, 'VERSION not provided' cwd = os.path.realpath('{}/../..'.format(os.path.dirname(__file__))) filename = '{}/packaging/bin/vault_{}_{}.deb'.format( cwd, version, Platform.arch) (code, result, error) = Shell.run([ "apt-get", "install", "-f", "-qq", "-o=Dpkg::Use-Pty=0", "-o=Dpkg::Options::=--force-confdef", "-o=Dpkg::Options::=--force-confnew", filename ]) if code != 'OK': raise RuntimeError('code: {}, stdout: [{}], stderr: [{}]'.format( code, result, error)) (code, result, error) = Shell.run( ["systemctl", "-t", "service", "--all", "--no-legend"]) if code != 'OK': raise RuntimeError('code: {}, stdout: [{}], stderr: [{}]'.format( code, result, error)) self.services = set([ item.replace( '*', '').strip().split(' ')[0].split('@')[0].split('.service')[0] for item in result.split(os.linesep) ])
def onboard_unit(context, tenant): (code, result, error) = Shell.run( ["systemctl", 'enable', 'vault-unit@{}'.format(tenant)]) assert code == 'OK', str(code) + ' ' + str(result) + ' ' + str(error) (code, result, error) = Shell.run(["systemctl", 'start', 'vault-unit@{}'.format(tenant)]) assert code == 'OK', str(code) + ' ' + str(result) + ' ' + str(error) unit_running(context, 'vault-unit@{}'.format(tenant))
def wait_for_import_to_stop(): (code, result, error) = Shell.run(["systemctl", "stop", "cnb-rates-import.service"]) assert code == 'OK', str(result) + ' ' + str(error) (code, result, error) = Shell.run([ "systemctl", "show", "-p", "SubState", 'cnb-rates-import.service' ]) assert code == 'OK', str(result) + ' ' + str(error) assert 'SubState=dead' in result, str(result) + ' ' + str(error)
def teardown(self): Shell.run(['timedatectl', 'set-local-rtc', '1']) Shell.run(['timedatectl', 'set-ntp', '1']) Shell.run(['systemctl', 'restart', 'systemd-timedated']) Shell.run(['systemctl', 'restart', 'systemd-timesyncd']) Shell.run([ 'timedatectl', 'set-time', self.__original_epoch.strftime('%Y-%m-%d %H:%M:%S') ])
def wait_for_import_to_start(): context.timeshift.set_date_time(context.new_epoch) context.new_epoch += datetime.timedelta(seconds=1) (code, result, error) = Shell.run(["systemctl", "restart", "cnb-rates-import.timer"]) assert code == 'OK', str(result) + ' ' + str(error) (code, result, error) = Shell.run([ "systemctl", "show", "-p", "SubState", 'cnb-rates-import.service' ]) assert code == 'OK', str(result) + ' ' + str(error) assert 'SubState=running' in result, str(result) + ' ' + str(error)
def teardown(self): units = ['vault-rest'] + ['vault-unit@{}'.format(tenant) for tenant in self.tenants] for unit in units: Shell.run(['systemctl', 'stop', unit]) (code, result, error) = Shell.run([ 'journalctl', '-o', 'cat', '-u', '{}.service'.format(unit), '--no-pager' ], True) if code != 'OK' or not result: continue filename = os.path.realpath('{}/../../reports/perf-tests/logs/{}.log'.format(os.path.dirname(os.path.abspath(__file__)), unit)) with open(filename, 'w') as f: f.write(result)
def set_date_time(self, new_epoch): (code, result, error) = Shell.run([ 'timedatectl', 'set-time', new_epoch.strftime('%Y-%m-%d %H:%M:%S') ]) assert code == 'OK', "timedatectl set-time failed with: {} {}".format( result, error)
def step_impl(context, package, operation): if operation == 'installed': (code, result, error) = Shell.run([ "apt-get", "install", "-f", "-qq", "-o=Dpkg::Use-Pty=0", "-o=Dpkg::Options::=--force-confold", context.unit.binary ]) assert code == 'OK', "unable to install with code {} and {} {}".format( code, result, error) assert os.path.isfile('/etc/fio-bco/conf.d/init.conf' ) is True, 'config file does not exists' Shell.run(['systemctl', 'start', package]) elif operation == 'uninstalled': Shell.run(['systemctl', 'stop', package]) (code, result, error) = Shell.run(["apt-get", "-f", "-qq", "remove", package]) assert code == 'OK', "unable to uninstall with code {} and {} {}".format( code, result, error) (code, result, error) = Shell.run(["apt-get", "-f", "-qq", "purge", package]) assert code == 'OK', "unable to purge with code {} and {} {}".format( code, result, error) assert os.path.isfile('/etc/fio-bco/conf.d/init.conf' ) is False, 'config file still exists' else: assert False, 'unknown operation {}'.format(operation)
def __get_systemd_units(self): (code, result, error) = Shell.run( ['systemctl', 'list-units', '--all', '--no-legend']) result = [ item.replace('*', '').strip().split(' ')[0].strip() for item in result.split(os.linesep) ] result = [item for item in result if "cnb-rates" in item] return result
def step_impl(context, package, operation): if operation == 'installed': (code, result, error) = Shell.run([ "apt-get", "install", "-f", "-qq", "-o=Dpkg::Use-Pty=0", "-o=Dpkg::Options::=--force-confold", context.unit.binary ]) assert code == 'OK', "unable to install with code {} and {} {}".format( code, result, error) assert os.path.isfile('/etc/cnb-rates/conf.d/init.conf') is True elif operation == 'uninstalled': (code, result, error) = Shell.run(["apt-get", "-y", "remove", package]) assert code == 'OK', "unable to uninstall with code {} and {} {}".format( code, result, error) (code, result, error) = Shell.run(["apt-get", "-y", "purge", package]) assert code == 'OK', "unable to purge with code {} and {} {}".format( code, result, error) assert os.path.isfile('/etc/cnb-rates/conf.d/init.conf') is False else: assert False, 'unknown operation {}'.format(operation)
def onboard(self, tenant) -> None: unit = 'vault-unit@{}'.format(tenant) (code, result, error) = Shell.run(["systemctl", 'enable', unit]) assert code == 'OK', str(result) + ' ' + str(error) (code, result, error) = Shell.run(["systemctl", 'start', unit]) assert code == 'OK', str(result) + ' ' + str(error) self.tenants.append(tenant) @eventually(30) def wait_for_running(): (code, result, error) = Shell.run([ "systemctl", "show", "-p", "SubState", unit ]) assert code == 'OK', str(result) + ' ' + str(error) assert 'SubState=running' in result wait_for_running()
def start(self) -> bool: (code, result, error) = Shell.run(['systemctl', 'start', 'lake-relay']) assert code == 'OK', str(code) + ' ' + str(result) + ' ' + str(error) @eventually(30) def wait_for_running(): (code, result, error) = Shell.run( ["systemctl", "show", "-p", "SubState", 'lake-relay']) assert code == 'OK', str(result) + ' ' + str(error) assert 'SubState=running' in result wait_for_running()
def __get_systemd_units(self): (code, result, error) = Shell.run( ['systemctl', 'list-units', '--all', '--no-legend']) result = [ item.replace('*', '').strip().split(' ')[0].strip() for item in result.split(os.linesep) ] result = [ item for item in result if "fio-bco" in item and not item.endswith('unit.slice') ] return result
def step_impl(context): (code, result, error) = Shell.run( ["systemctl", "list-units", "--all", "--no-legend", "--state=active"]) assert code == 'OK', str(result) + ' ' + str(error) items = [] for row in context.table: items.append(row['name'] + '.' + row['type']) result = [ item.replace('*', '').strip().split(' ')[0].strip() for item in result.split(os.linesep) ] result = [item for item in result if item in items] assert len(result) == 0, 'units {} found'.format(result)
def start(self) -> bool: units = ['vault-rest'] + ['vault-unit@{}'.format(tenant) for tenant in self.tenants] for unit in units: (code, result, error) = Shell.run(['systemctl', 'start', unit]) assert code == 'OK', str(result) + ' ' + str(error) @eventually(30) def wait_for_running(): (code, result, error) = Shell.run([ "systemctl", "show", "-p", "SubState", unit ]) assert code == 'OK', str(result) + ' ' + str(error) assert 'SubState=running' in result wait_for_running()
def offboard_unit(context, tenant): logfile = os.path.realpath( '{}/../../reports/blackbox-tests/logs/vault-unit.{}.log'.format( os.path.dirname(__file__), tenant)) (code, result, error) = Shell.run([ 'journalctl', '-o', 'cat', '-u', 'vault-unit@{}.service'.format(tenant), '--no-pager' ]) if code == 'OK' and result: with open(logfile, 'w') as f: f.write(result) Shell.run(['systemctl', 'stop', 'vault-unit@{}.service'.format(tenant)]) (code, result, error) = Shell.run([ 'journalctl', '-o', 'cat', '-u', 'vault-unit@{}.service'.format(tenant), '--no-pager' ]) if code == 'OK' and result: with open(logfile, 'w') as fd: fd.write(result) Shell.run(['systemctl', 'disable', 'vault-unit@{}.service'.format(tenant)]) unit_not_running(context, 'vault-unit@{}'.format(tenant))
def bootstrap(self): Shell.run(['timedatectl', 'set-ntp', '0']) Shell.run(['timedatectl', 'set-local-rtc', '0'])
def stop(self) -> bool: (code, result, error) = Shell.run(['systemctl', 'stop', 'lake-relay']) assert code == 'OK', str(code) + ' ' + str(result) + ' ' + str(error)
def operation_unit(context, operation, unit): (code, result, error) = Shell.run(["systemctl", operation, unit]) assert code == 'OK', str(result) + ' ' + str(error)
def wait_for_unit_state_change(): (code, result, error) = Shell.run(["systemctl", "show", "-p", "SubState", unit]) assert code == 'OK', str(result) + ' ' + str(error) assert 'SubState=dead' in result, result
def wait_for_running(): (code, result, error) = Shell.run([ "systemctl", "show", "-p", "SubState", unit ]) assert code == 'OK', str(result) + ' ' + str(error) assert 'SubState=running' in result
'{}/../reports/blackbox-tests/metrics'.format(cwd), '{}/../reports/blackbox-tests/logs'.format(cwd), '{}/../reports/blackbox-tests/meta'.format(cwd), '{}/../reports/blackbox-tests/behave'.format(cwd), '{}/../reports/blackbox-tests/cucumber'.format(cwd), '{}/../reports/blackbox-tests/junit'.format(cwd) ]: os.system('mkdir -p {}'.format(path)) os.system('rm -rf {}/*'.format(path)) from behave import __main__ as behave_executable print('\nStarting tests') exit_code = behave_executable.main(args=' '.join(args)) with open('{}/../reports/blackbox-tests/behave/results.json'.format(cwd), 'r') as fd_behave: cucumber_data = None with open('{}/../reports/blackbox-tests/cucumber/results.json'.format(cwd), 'w') as fd_cucumber: behave_data = json.loads(fd_behave.read()) cucumber_data = json.dumps(behave2cucumber.convert(behave_data)) fd_cucumber.write(cucumber_data) Shell.run([ 'json_to_junit', '{}/../reports/blackbox-tests/cucumber/results.json'.format(cwd), '{}/../reports/blackbox-tests/junit/results.xml'.format(cwd) ]) sys.exit(exit_code)
def stop(self) -> bool: units = ['vault-rest'] + ['vault-unit@{}'.format(tenant) for tenant in self.tenants] for unit in units: (code, result, error) = Shell.run(['systemctl', 'stop', unit]) assert code == 'OK', str(result) + ' ' + str(error)
def teardown(self): self.collect_logs() for unit in self.__get_systemd_units(): Shell.run(['systemctl', 'stop', unit]) self.collect_logs()