Skip to content

Commit

Permalink
* [e2e] fix bugs in schedule_on_maximum
Browse files Browse the repository at this point in the history
  • Loading branch information
lanfon72 committed Oct 26, 2023
1 parent 4f510e8 commit 386fbe4
Showing 1 changed file with 38 additions and 25 deletions.
63 changes: 38 additions & 25 deletions harvester_e2e_tests/integration/test_vm_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,14 @@ def test_create_schedule_on_maximum(
f"VM started but not hosted on expected host: {expected_host}"
)
else:
# ???: node's resources released while creating VM, so the VM be hosted on others
assert expected_host in [name for name, _ in schedulables], (
# ???: node's resources released while creating VM
expected_conditions = [
# VM still be hosted on expected host
expected_host == vmi['status']['nodeName'],
# VM be hosted on others
expected_host in [name for name, _ in schedulables],
]
assert any(expected_conditions), (
f"VM started on another host {vmi['status']['nodeName']},"
f" and the resource of expected host {expected_host!r} be updated."
)
Expand Down Expand Up @@ -707,29 +713,36 @@ def test_update_schedule_on_maximum(
for k, resource in data['spec']['template']['spec']['domain']['resources'].items():
resource[res_type] = vm_calc.format_unit(expected_res, max_exp=exp, suffix_space=False)

code, data = api_client.vms.update(unique_vm_name, data)
assert 200 == code, (code, data)
vm_started, (code, vmi) = vm_checker.wait_started(unique_vm_name)
assert vm_started, (code, vmi)

# Verify the VM be hosted expected
code, hosts = api_client.hosts.get()
cur_res = [(n['metadata']['name'], vm_calc.node_resources(n)['schedulable'])
for n in hosts['data']]
schedulables = [(name, res) for (name, res) in cur_res if res[res_type] > expected_res]
if not schedulables:
# General case
assert expected_host == vmi['status']['nodeName'], (
f"VM started but not hosted on expected host: {expected_host}"
)
else:
# ???: node's resources released while creating VM, so the VM be hosted on others
assert expected_host in [name for name, _ in schedulables], (
f"VM started on another host {vmi['status']['nodeName']},"
f" and the resource of expected host {expected_host!r} be updated."
)
# Stop the VM
vm_checker.wait_stopped(unique_vm_name)
try:
code, data = api_client.vms.update(unique_vm_name, data)
assert 200 == code, (code, data)
vm_started, (code, vmi) = vm_checker.wait_started(unique_vm_name)
assert vm_started, (code, vmi)

# Verify the VM be hosted expected
code, hosts = api_client.hosts.get()
cur_res = [(n['metadata']['name'], vm_calc.node_resources(n)['schedulable'])
for n in hosts['data']]
schedulables = [(name, res) for (name, res) in cur_res if res[res_type] > expected_res]
if not schedulables:
# General case
assert expected_host == vmi['status']['nodeName'], (
f"VM started but not hosted on expected host: {expected_host}"
)
else:
# ???: node's resources released while creating VM, so the VM be hosted on others
assert expected_host in [name for name, _ in schedulables], (
f"VM started on another host {vmi['status']['nodeName']},"
f" and the resource of expected host {expected_host!r} be updated."
)
finally:
# Stop the VM
vm_checker.wait_stopped(unique_vm_name)
# Revert the VM to request minimal resource
code, data = api_client.vms.get(unique_vm_name)
vm_spec._data = data
code, data = api_client.vms.update(unique_vm_name, vm_spec)
assert 200 == code, (code, data)

def test_update_cpu(
self, api_client, ssh_keypair, vm_shell_from_host, vm_checker,
Expand Down

0 comments on commit 386fbe4

Please sign in to comment.