Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[e2e] fix upgrade bugs #1248

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apiclient/harvester_api/managers/storageclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def get(self, name="", *, raw=False, **kwargs):
def get_default(self):
code, data = self.get()
for sc in data['items']:
if 'true' == sc['metadata']['annotations'].get(DEFAULT_STORAGE_CLASS_ANNOTATION):
if 'true' == sc['metadata'].get('annotations', {}).get(
DEFAULT_STORAGE_CLASS_ANNOTATION):
return code, sc
else:
return code, data
Expand Down
38 changes: 16 additions & 22 deletions harvester_e2e_tests/integrations/test_upgrade.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import re
import json
import yaml
import socket
from time import sleep
from operator import add
from functools import reduce
Expand Down Expand Up @@ -240,22 +239,6 @@ def check(self, data):
for func in self.intercepts():
func(data)

def intercept_v121_vm(self, data):
if "v1.2.1" != api_client.cluster_version.raw:
return
if self._v121_vm:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps also drop class variable _v121_vm (Line 232) since it's only referenced by intercept_v121_vm?

code, data = api_client.vms.get()
for vm in data.get('data', []):
api_client.vms.stop(vm['metadata']['name'])
self._v121_vm = False
else:
conds = dict((c['type'], c) for c in data.get('status', {}).get('conditions', []))
st = data.get('metadata', {}).get('labels', {}).get('harvesterhci.io/upgradeState')
if "Succeeded" == st and "True" == conds.get('Completed', {}).get('status'):
code, data = api_client.vms.get()
for vm in data.get('data', []):
api_client.vms.start(vm['metadata']['name'])

return Interceptor()


Expand Down Expand Up @@ -612,7 +595,7 @@ def test_preq_setup_vms(
)
assert not err, (vm1_md5, err)
break
except (SSHException, NoValidConnectionsError):
except (SSHException, NoValidConnectionsError, TimeoutError):
sleep(5)
else:
raise AssertionError("Timed out while writing data into VM")
Expand All @@ -635,6 +618,17 @@ def test_preq_setup_vms(
spec = api_client.backups.RestoreSpec.for_new(restored_vm_name)
code, data = api_client.backups.restore(unique_vm_name, spec)
assert 201 == code, (code, data)
# Check restore VM is created
endtime = datetime.now() + timedelta(seconds=wait_timeout)
while endtime > datetime.now():
code, data = api_client.vms.get(restored_vm_name)
if 200 == code:
break
sleep(3)
else:
raise AssertionError(
f"restored VM {restored_vm_name} is not created"
)
vm_got_ips, (code, data) = vm_checker.wait_interfaces(restored_vm_name)
assert vm_got_ips, (
f"Failed to Start VM({restored_vm_name}) with errors:\n"
Expand All @@ -660,7 +654,7 @@ def test_preq_setup_vms(
)
assert "success" == out and not err
break
except (SSHException, NoValidConnectionsError):
except (SSHException, NoValidConnectionsError, TimeoutError):
sleep(5)
else:
raise AssertionError("Unable to login to restored VM to check data consistency")
Expand Down Expand Up @@ -771,7 +765,7 @@ def test_verify_audit_log(self, api_client, host_shell, wait_timeout):
continue
if not err and cmp[ip] < timestamp:
done.add(ip)
except (SSHException, NoValidConnectionsError, socket.timeout):
except (SSHException, NoValidConnectionsError, TimeoutError):
continue

if not done.symmetric_difference(node_ips):
Expand Down Expand Up @@ -851,7 +845,7 @@ def test_verify_vms(self, api_client, cluster_state, vm_shell, vm_checker, wait_
assert not err, (md5, err)
assert md5 == cluster_state.vms['md5']
break
except (SSHException, NoValidConnectionsError):
except (SSHException, NoValidConnectionsError, TimeoutError):
sleep(5)
else:
fails.append(f"Data in VM({name}, {vm_ip}) is inconsistent.")
Expand Down Expand Up @@ -907,7 +901,7 @@ def test_verify_restore_vm(
assert not err, (md5, err)
assert md5 == cluster_state.vms['md5']
break
except (SSHException, NoValidConnectionsError):
except (SSHException, NoValidConnectionsError, TimeoutError):
sleep(5)
else:
raise AssertionError("Unable to login to restored VM to check data consistency")
Expand Down