-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migration: Support multiple hosts migration
Signed-off-by: Yongxue Hong <[email protected]>
- Loading branch information
1 parent
e8c8bbd
commit 8df2176
Showing
35 changed files
with
1,851 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import logging | ||
import os | ||
import sys | ||
|
||
from avocado.core import exit_codes | ||
from avocado.core.plugin_interfaces import JobPostTests as Post | ||
from avocado.core.plugin_interfaces import JobPreTests as Pre | ||
from avocado.utils.stacktrace import log_exc_info | ||
from virttest.vt_cluster import cluster, node_metadata | ||
|
||
|
||
class ClusterSetupError(Exception): | ||
""" | ||
Represents any error situation when attempting to create a cluster. | ||
""" | ||
|
||
pass | ||
|
||
|
||
class ClusterManagerSetupError(ClusterSetupError): | ||
pass | ||
|
||
|
||
class ClusterCleanupError(Exception): | ||
pass | ||
|
||
|
||
class ClusterManagerCleanupError(ClusterCleanupError): | ||
pass | ||
|
||
|
||
class VTCluster(Pre, Post): | ||
|
||
name = "vt-cluster" | ||
description = "Avocado-VT Cluster Pre/Post" | ||
|
||
def __init__(self, **kwargs): | ||
self._log = logging.getLogger("avocado.app") | ||
|
||
@staticmethod | ||
def _pre_node_setup(): | ||
try: | ||
for node in cluster.get_all_nodes(): | ||
node.start_agent_server() | ||
node_metadata.load_metadata() | ||
except Exception as err: | ||
raise ClusterSetupError(err) | ||
|
||
@staticmethod | ||
def _pre_mgr_setup(): | ||
try: | ||
# Pre-setup the cluster manager | ||
# e.g: | ||
# startup_resmgr() | ||
# vt_imgr.startup() | ||
pass | ||
except Exception as err: | ||
raise ClusterManagerSetupError(err) | ||
|
||
@staticmethod | ||
def _post_mgr_cleanup(): | ||
try: | ||
# Post-cleanup the cluster manager | ||
# e.g: | ||
# teardown_resmgr() | ||
# vt_imgr.teardown() | ||
pass | ||
except Exception as err: | ||
raise ClusterManagerCleanupError(err) | ||
|
||
def _post_node_setup(self, job): | ||
cluster_dir = os.path.join(job.logdir, "cluster") | ||
for node in cluster.get_all_nodes(): | ||
node_dir = os.path.join(cluster_dir, node.name) | ||
os.makedirs(node_dir) | ||
try: | ||
node.upload_agent_log(node_dir) | ||
except Exception as err: | ||
self._log.warning(err) | ||
finally: | ||
try: | ||
node.stop_agent_server() | ||
except Exception as detail: | ||
err = ClusterCleanupError(detail) | ||
msg = ( | ||
f"Failed to stop the agent " | ||
f"server on node '{node.name}': {err}" | ||
) | ||
self._log.warning(msg) | ||
node_metadata.unload_metadata() | ||
|
||
def pre_tests(self, job): | ||
if cluster.get_all_nodes(): | ||
try: | ||
self._pre_node_setup() | ||
self._pre_mgr_setup() | ||
except Exception as detail: | ||
msg = "Failure trying to set Avocado-VT job env: %s" % detail | ||
self._log.error(msg) | ||
log_exc_info(sys.exc_info(), self._log.name) | ||
sys.exit(exit_codes.AVOCADO_JOB_FAIL | job.exitcode) | ||
|
||
def post_tests(self, job): | ||
if cluster.get_all_nodes(): | ||
try: | ||
self._post_mgr_cleanup() | ||
except ClusterManagerCleanupError as err: | ||
self._log.warning(err) | ||
finally: | ||
self._post_node_setup(job) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
- vt_node_test: | ||
type = vt_node_test | ||
start_vm = no | ||
not_preprocess = yes | ||
nodes = node1 node2 node3 | ||
node_selectors_node1 = [{"key": "cpu_vendor_id", "operator": "eq", "values": "AuthenticAMD"}, | ||
node_selectors_node1 += {"key": "hostname", "operator": "contains", "values": "redhat.com"}] | ||
node_selectors_node2 = [{"key": "cpu_vendor_id", "operator": "==", "values": "AuthenticAMD"}, | ||
node_selectors_node2 += {"key": "hostname", "operator": "contains", "values": "redhat.com"}] | ||
node_selectors_node3 = [{"key": "cpu_vendor_id", "operator": "==", "values": "AuthenticAMD"}, | ||
node_selectors_node3 += {"key": "hostname", "operator": "contains", "values": "redhat.com"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
Simple vt node handling test. | ||
Please put the configuration file vt_node_test.cfg into $tests/cfg/ directory. | ||
""" | ||
|
||
|
||
def run(test, params, env): | ||
for node in test.nodes: | ||
test.log.info("========Start test on %s========", node.name) | ||
node.proxy.unittest.hello.say() | ||
node.proxy.unittest.testcase.vm.boot_up() | ||
test.log.info("========End test========") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import sys | ||
|
||
from .core.data_dir import BASE_DIR | ||
|
||
sys.path.append(BASE_DIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
# | ||
# See LICENSE for more details. | ||
# | ||
# Copyright: Red Hat Inc. 2022 | ||
# Authors: Yongxue Hong <[email protected]> | ||
|
||
""" | ||
Main entry point when called by 'python -m'. | ||
""" | ||
|
||
import os | ||
import shutil | ||
|
||
from .app.args import init_arguments | ||
from .app.cmd import run | ||
from .core.logger import init_logger | ||
from .core.data_dir import LOG_DIR | ||
|
||
args = init_arguments() | ||
|
||
try: | ||
shutil.rmtree(LOG_DIR) | ||
os.remove(args.pid_file) | ||
except (FileNotFoundError, OSError): | ||
pass | ||
|
||
os.makedirs(LOG_DIR) | ||
|
||
root_logger = init_logger() | ||
|
||
if __name__ == "__main__": | ||
run(args.host, args.port, args.pid_file) |
Oops, something went wrong.