Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ilia1243 committed Jan 11, 2024
1 parent 92ed90a commit ba0f773
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/unit/core/test_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ def test_detect_nodes_context(self):
"Here should be all 4 calls of test_func")

self.assertEqual("rhel", cluster.get_os_family())
self.assertEqual(len(hosts), len(cluster.nodes_context))
for host, node_context in cluster.nodes_context.items():
self.assertEqual({'online': True, 'accessible': True, 'sudo': 'Root'}, node_context["access"])
self.assertEqual({'name': 'centos', 'version': '7.6', 'family': 'rhel'}, node_context["os"])
Expand Down Expand Up @@ -332,6 +333,22 @@ def test_any_offline_node_interrupts(self):
self.assertIsInstance(exc, errors.FailException, msg="Exception should be raised")
self.assertTrue(f"['{offline}'] are not reachable." in str(exc.reason))

def test_all_nodes_offline_check_iaas(self):
inventory = demo.generate_inventory(**demo.FULLHA_KEEPALIVED)
self._stub_detect_nodes_context(inventory, [], [])
context = demo.create_silent_context(procedure='check_iaas')
res = demo.FakeResources(context, inventory, fake_shell=self.light_fake_shell)
flow.run_tasks(res, tasks)
cluster = res.cluster()
self.assertEqual(4, cluster.context["test_info"],
"Here should be all 4 calls of test_func")

self.assertEqual("<undefined>", cluster.get_os_family())
for host, node_context in cluster.nodes_context.items():
self.assertEqual({'online': False, 'accessible': False, 'sudo': "No"}, node_context["access"])
self.assertEqual({'name': "<undefined>", 'version': "<undefined>", 'family': "<undefined>"}, node_context["os"])
self.assertEqual("<undefined>", node_context["active_interface"])

def test_any_removed_node_can_be_offline(self):
inventory = demo.generate_inventory(**demo.FULLHA_KEEPALIVED)
online_hosts = [node["address"] for node in inventory["nodes"]]
Expand All @@ -349,6 +366,31 @@ def test_any_removed_node_can_be_offline(self):
# no exception should occur
flow.run_tasks(res, tasks)

def test_detect_nodes_context_removed_node_online(self):
inventory = demo.generate_inventory(**demo.FULLHA_KEEPALIVED)
hosts = [node["address"] for node in inventory["nodes"]]
self._stub_detect_nodes_context(inventory, hosts, hosts)

i = random.randrange(len(inventory["nodes"]))
procedure_inventory = demo.generate_procedure_inventory('remove_node')
procedure_inventory["nodes"] = [{"name": inventory["nodes"][i]["name"]}]

context = demo.create_silent_context(['fake_path.yaml'], procedure='remove_node')
res = demo.FakeResources(context, inventory, procedure_inventory=procedure_inventory,
fake_shell=self.light_fake_shell)

flow.run_tasks(res, tasks)
cluster = res.cluster()
self.assertEqual(4, cluster.context["test_info"],
"Here should be all 4 calls of test_func")

self.assertEqual("rhel", cluster.get_os_family())
self.assertEqual(len(hosts), len(cluster.nodes_context))
for host, node_context in cluster.nodes_context.items():
self.assertEqual({'online': True, 'accessible': True, 'sudo': 'Root'}, node_context["access"])
self.assertEqual({'name': 'centos', 'version': '7.6', 'family': 'rhel'}, node_context["os"])
self.assertEqual('eth0', node_context["active_interface"])

def test_kubernetes_version_not_allowed(self):
k8s_versions = list(sorted(static.KUBERNETES_VERSIONS["compatibility_map"], key=utils.version_key))
k8s_latest = k8s_versions[-1]
Expand Down

0 comments on commit ba0f773

Please sign in to comment.