-
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
28a2351
commit 9ce3ff0
Showing
31 changed files
with
1,694 additions
and
0 deletions.
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,53 @@ | ||
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 ClusterCreationError(Exception): | ||
""" | ||
Represents any error situation when attempting to create a cluster. | ||
""" | ||
|
||
pass | ||
|
||
|
||
class VTCluster(Pre, Post): | ||
|
||
name = "vt-cluster" | ||
description = "Avocado-VT Cluster Pre/Post" | ||
|
||
def __init__(self, **kwargs): | ||
self._log = logging.getLogger("avocado.app") | ||
|
||
def pre_tests(self, job): | ||
if cluster.get_all_nodes(): | ||
try: | ||
for node in cluster.get_all_nodes(): | ||
node.start_agent_server() | ||
node_metadata.load_metadata() | ||
|
||
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(): | ||
cluster_dir = os.path.join(job.logdir, "cluster") | ||
for node in cluster.get_all_nodes(): | ||
try: | ||
node_dir = os.path.join(cluster_dir, node.name) | ||
os.makedirs(node_dir) | ||
node.upload_agent_log(node_dir) | ||
node.stop_agent_server() | ||
except Exception: | ||
pass | ||
node_metadata.unload_metadata() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import os | ||
import sys | ||
|
||
BASE_DIR = os.path.dirname(__file__) | ||
LOG_DIR = os.path.join(BASE_DIR, "log") | ||
AGENT_LOG_FILENAME = os.path.join(LOG_DIR, "agent.log") | ||
SERVICE_LOG_FILENAME = os.path.join(LOG_DIR, "service.log") | ||
LOG_FORMAT = "%(asctime)s %(name)s %(levelname)-5.5s| %(message)s" | ||
|
||
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 . import LOG_DIR | ||
from .app.args import init_arguments | ||
from .app.cmd import run | ||
from .core.logger import init_logger | ||
|
||
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) |
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,71 @@ | ||
# 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]> | ||
|
||
import logging.handlers | ||
import os | ||
import signal | ||
|
||
from . import AGENT_LOG_FILENAME, LOG_FORMAT, SERVICE_LOG_FILENAME | ||
|
||
LOG = logging.getLogger("avocado.agent." + __name__) | ||
|
||
|
||
def quit(): | ||
"""Quit the agent server.""" | ||
pid = os.getpid() | ||
LOG.info("Quit the server daemon(PID:%s).", pid) | ||
os.kill(pid, signal.SIGKILL) | ||
|
||
|
||
def is_alive(): | ||
"""Check whether the agent server is alive.""" | ||
LOG.info("The server daemon is alive.") | ||
return True | ||
|
||
|
||
def start_logger_client(host, port): | ||
"""Start the agent logger client""" | ||
try: | ||
os.remove(SERVICE_LOG_FILENAME) | ||
except FileNotFoundError: | ||
pass | ||
|
||
logger = logging.getLogger("avocado.service") | ||
logger.setLevel(logging.DEBUG) | ||
file_handler = logging.FileHandler(filename=SERVICE_LOG_FILENAME) | ||
file_handler.setFormatter(logging.Formatter(fmt=LOG_FORMAT)) | ||
logger.addHandler(file_handler) | ||
|
||
LOG.info("Start the logger client.") | ||
socket_handler = logging.handlers.SocketHandler(host, port) | ||
socket_handler.setLevel(logging.DEBUG) | ||
logger.addHandler(socket_handler) | ||
|
||
|
||
def stop_logger_client(): | ||
"""Stop the agent logger client.""" | ||
LOG.info("Stop the logger client.") | ||
for handler in logging.getLogger("avocado.service").handlers: | ||
handler.close() | ||
logging.getLogger("avocado.service").handlers.clear() | ||
|
||
|
||
def get_agent_log_filename(): | ||
"""Get the filename of the agent log.""" | ||
return AGENT_LOG_FILENAME | ||
|
||
|
||
def get_service_log_filename(): | ||
"""Get the filename of the service log.""" | ||
return SERVICE_LOG_FILENAME |
Empty file.
Oops, something went wrong.