From aec43105089dc65f0f0b32a19aabbd5e1cc58207 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 3 Nov 2023 18:51:23 +0100 Subject: [PATCH 1/5] define PLC_MAIL_FROM_ADDRESS --- system/config_default.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/system/config_default.py b/system/config_default.py index d38b622..82331d3 100644 --- a/system/config_default.py +++ b/system/config_default.py @@ -504,6 +504,9 @@ def plc (options, index) : 'PLC_SHORTNAME' : 'Tlab', 'PLC_MAIL_ENABLED' : 'false', 'PLC_MAIL_SUPPORT_ADDRESS' : 'thierry.parmentelat@inria.fr', + # in the real word, use root@host.domain + # like e.g. root@r2labapi.inria.fr + 'PLC_MAIL_FROM_ADDRESS' : 'thierry.parmentelat@inria.fr', 'PLC_DB_HOST' : 'deferred-myplc-hostname', # 'PLC_DB_PASSWORD' : 'mnbvcxzlkjhgfdsapoiuytrewq', 'PLC_API_HOST' : 'deferred-myplc-hostname', -- 2.51.1 From 0de2cf26036895afb48d0c5c8edf76c49215070e Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Mon, 23 Sep 2024 18:32:20 +0200 Subject: [PATCH 2/5] add test gor GetSlices with the ALL keyword --- system/plcsh_stress_test.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/system/plcsh_stress_test.py b/system/plcsh_stress_test.py index f64dbe8..1dc6e97 100755 --- a/system/plcsh_stress_test.py +++ b/system/plcsh_stress_test.py @@ -1683,7 +1683,11 @@ class Test: self.api.DeleteSlice(slice_id) if self.check: + # Check that slice is gone assert not self.api.GetSlices([slice_id]) + # but we can still retrieve it with the ALL filter + assert len(self.api.GetSlices( + {'slice_id': slice_id, 'ALL': True})) == 1 if self.verbose: print("Deleted slice", slice_id) -- 2.51.1 From c326c934210c6c9378578e78f54bc74ac63e3237 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Tue, 24 Sep 2024 10:12:23 +0200 Subject: [PATCH 3/5] adaptations to plcapi 7.2.1 --- system/plcsh_stress_test.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/system/plcsh_stress_test.py b/system/plcsh_stress_test.py index 1dc6e97..6479a06 100755 --- a/system/plcsh_stress_test.py +++ b/system/plcsh_stress_test.py @@ -1685,9 +1685,13 @@ class Test: if self.check: # Check that slice is gone assert not self.api.GetSlices([slice_id]) + assert not self.api.GetSlices( + {'slice_id': slice_id, 'EXPIRED':True}) # but we can still retrieve it with the ALL filter assert len(self.api.GetSlices( - {'slice_id': slice_id, 'ALL': True})) == 1 + {'slice_id': slice_id, 'DELETED': True})) == 1 + assert len(self.api.GetSlices( + {'slice_id': slice_id, 'DELETED': True, 'EXPIRED': True})) == 1 if self.verbose: print("Deleted slice", slice_id) -- 2.51.1 From e742ac58292005593565acd12b82051affa08996 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Mon, 14 Oct 2024 18:55:22 +0200 Subject: [PATCH 4/5] plcsh_test_leases.py is a utility script but not yet integrated in daily build --- system/plcsh_test_leases.py | 113 ++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100755 system/plcsh_test_leases.py diff --git a/system/plcsh_test_leases.py b/system/plcsh_test_leases.py new file mode 100755 index 0000000..22eb5d6 --- /dev/null +++ b/system/plcsh_test_leases.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python + +""" +a utility used in oct 2024 while checking the deletion of leases by slices +not integrated in the nightly yet +""" + +import sys +sys.path.append('/usr/share/plc_api') + +from PLC.Shell import Shell + +api = Shell() + +# our test plc has one site only if we ignore the auto site + +def populate(expires: False): + + login_base = 'reserv' + + try: + site_id = api.AddSite({ + 'name': "a site for hosting reservable nodes", + 'abbreviated_name': "res_site", + 'login_base': login_base, + 'max_slices': 100, + }) + except: + print("the site already exists") + site_id = api.GetSites({'login_base': login_base})[0]['site_id'] + + try: + node_id = api.AddNode(site_id, { + 'hostname': f'leases.testplc.org', + 'node_type': 'reservable', + }) + except: + print("the node already exists") + node_id = api.GetNodes({'hostname': 'leases.testplc.org'})[0]['node_id'] + + try: + slice_id = api.AddSlice({'name': f'{login_base}_leases'}) + if expires: + import time + now = int(time.time()) + slice_expires = {'expires': now + 30} + api.UpdateSlice(slice_id, slice_expires) + + except: + print("the slice already exists") + slice_id = api.GetSlices({'name': f'{login_base}_leases'})[0]['slice_id'] + + # create a lease + leases = api.AddLeases( + node_id, + slice_id, + '2025-01-01 00:00:00', + '2025-01-01 01:00:00', + ) + try: + lease_id = leases['new_ids'][0] + except: + print("the lease already exists") + lease_id = api.GetLeases({'hostname': 'leases.testplc.org'})[0]['lease_id'] + print(f"{site_id=}, {node_id=}, {slice_id=} {lease_id=}") + + +def unpopulate(full=False): + """ + our main objective is to see what happens when a slice is deleted + however for testing it is somtimes useful to clean up the full mounty + """ + + if full: + leases = api.GetLeases({'hostname': 'leases.testplc.org'}) + if not leases: + print("the lease was deleted already") + else: + api.DeleteLeases([leases[0]['lease_id']]) + + slices = api.GetSlices({'name': 'reserv_leases'}) + if not slices: + print("the slice was deleted already") + else: + api.DeleteSlice(slices[0]['slice_id']) + + if full: + nodes = api.GetNodes({'hostname': 'leases.testplc.org'}) + if not nodes: + print("the node was deleted already") + else: + api.DeleteNode(nodes[0]['node_id']) + + if full: + sites = api.GetSites({'login_base': 'reserv'}) + if not sites: + print("the site was deleted already") + else: + api.DeleteSite(sites[0]['site_id']) + + +from argparse import ArgumentParser +parser = ArgumentParser() +parser.add_argument('-p', '--populate', action='store_true') +parser.add_argument('-e', '--expires', action='store_true', help='make the slice expire in 30') +parser.add_argument('-u', '--unpopulate', action='store_true') +parser.add_argument('-f', '--full', action='store_true', help='unpopulate everything, not just the slice') +args = parser.parse_args() + +if args.populate: + populate(expires=args.expires) +if args.unpopulate: + unpopulate(full=args.full) -- 2.51.1 From a93e93b51b55ae4b38a4508ce68f994a8a3a26ee Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Tue, 26 Nov 2024 16:49:32 +0100 Subject: [PATCH 5/5] re.compile arguments made raw-strings for py-3.13 --- system/Substrate.py | 12 ++++++------ system/TestPlc.py | 2 +- system/template-qemu/iptables.py | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/system/Substrate.py b/system/Substrate.py index 2ab6c89..d531cfb 100644 --- a/system/Substrate.py +++ b/system/Substrate.py @@ -459,8 +459,8 @@ class BuildBox (Box): else: self.soft_reboot (options) -build_matcher=re.compile("\s*(?P[0-9]+).*-[bo]\s+(?P[^\s]+)(\s|\Z)") -build_matcher_initvm=re.compile("\s*(?P[0-9]+).*initvm.*\s+(?P[^\s]+)\s*\Z") +build_matcher=re.compile(r"\s*(?P[0-9]+).*-[bo]\s+(?P[^\s]+)(\s|\Z)") +build_matcher_initvm=re.compile(r"\s*(?P[0-9]+).*initvm.*\s+(?P[^\s]+)\s*\Z") class BuildLxcBox (BuildBox): def soft_reboot (self, options): @@ -743,7 +743,7 @@ class QemuBox (Box): self.run_ssh(['pkill','qemu'], "Killing qemu instances", dry_run=options.dry_run) - matcher=re.compile("\s*(?P[0-9]+).*-cdrom\s+(?P[^\s]+)\.iso") + matcher=re.compile(r"\s*(?P[0-9]+).*-cdrom\s+(?P[^\s]+)\.iso") def sense(self, options): print('qn', end=' ') @@ -927,9 +927,9 @@ class TestBox(Box): self.test_instances.append(i) i.set_broken(plcindex, step) - matcher_proc=re.compile (".*/proc/(?P[0-9]+)/cwd.*/root/(?P[^/]+)$") - matcher_grep=re.compile ("/root/(?P[^/]+)/logs/trace.*:TRACE:\s*(?P[0-9]+).*step=(?P\S+).*") - matcher_grep_missing=re.compile ("grep: /root/(?P[^/]+)/logs/trace: No such file or directory") + matcher_proc=re.compile(r".*/proc/(?P[0-9]+)/cwd.*/root/(?P[^/]+)$") + matcher_grep=re.compile(r"/root/(?P[^/]+)/logs/trace.*:TRACE:\s*(?P[0-9]+).*step=(?P\S+).*") + matcher_grep_missing=re.compile(r"grep: /root/(?P[^/]+)/logs/trace: No such file or directory") def sense(self, options): print('tm', end=' ') diff --git a/system/TestPlc.py b/system/TestPlc.py index 9cf5a2f..e7b41f6 100644 --- a/system/TestPlc.py +++ b/system/TestPlc.py @@ -1619,7 +1619,7 @@ class TestPlc: return True utils.header("********** Regular yum failed - special workaround in place, 2nd chance") code, cached_rpm_path = \ - utils.output_of(self.actual_command_in_guest('find /var/cache/yum -name sfa-client\*.rpm')) + utils.output_of(self.actual_command_in_guest(r'find /var/cache/yum -name sfa-client\*.rpm')) utils.header("rpm_path=<<{}>>".format(rpm_path)) # just for checking self.run_in_guest("rpm -i {}".format(cached_rpm_path)) diff --git a/system/template-qemu/iptables.py b/system/template-qemu/iptables.py index d694878..ded7e17 100755 --- a/system/template-qemu/iptables.py +++ b/system/template-qemu/iptables.py @@ -9,9 +9,9 @@ def main(): ip = sys.argv[3] found = False - lo_matcher = re.compile("\A(?P.+)\s+-i\s+lo\s+-j\s+ACCEPT") + lo_matcher = re.compile(r"\A(?P.+)\s+-i\s+lo\s+-j\s+ACCEPT") # what comes out of iptables-save has short-options syntax - ip_matcher = re.compile(".*-(s|d) %s" % ip) + ip_matcher = re.compile(r".*-(s|d) %s" % ip) for line in fin.readlines(): attempt = lo_matcher.match(line) if attempt: -- 2.51.1