本文整理汇总了Python中infrasim.workspace.Workspace类的典型用法代码示例。如果您正苦于以下问题:Python Workspace类的具体用法?Python Workspace怎么用?Python Workspace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Workspace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_stop_stop
def test_stop_stop(self):
"""
CLI test: stop a node will hint it's already stopped
"""
output_start = run_command("infrasim node start")
self.assertEqual(output_start[0], 0)
self.assertTrue(Workspace.check_workspace_exists(self.node_name))
output_stop_1 = run_command("infrasim node stop")
self.assertEqual(output_stop_1[0], 0)
self.assertTrue(Workspace.check_workspace_exists(self.node_name))
output_stop_2 = run_command("infrasim node stop")
self.assertEqual(output_stop_2[0], 0)
self.assertTrue(Workspace.check_workspace_exists(self.node_name))
assert "{}-socat is running".format(self.node_name) in output_start[1]
assert "{}-bmc is running".format(self.node_name) in output_start[1]
assert "{}-node is running".format(self.node_name) in output_start[1]
assert "{}-socat is stopped".format(self.node_name) in output_stop_1[1]
assert "{}-bmc is stopped".format(self.node_name) in output_stop_1[1]
assert "{}-node is stopped".format(self.node_name) in output_stop_1[1]
assert "{}-node is stopped".format(self.node_name) in output_stop_2[1]
assert "{}-bmc is stopped".format(self.node_name) in output_stop_2[1]
assert "{}-socat is stopped".format(self.node_name) in output_stop_2[1]
示例2: destroy
def destroy(self, node_name):
if Workspace.check_workspace_exists(node_name):
try:
node_info = Workspace.get_node_info_in_workspace(node_name)
except InfraSimError, e:
print e.value
logger_cmd.error("cmd res: {}".format(e.value))
return
示例3: start
def start(self, node_name):
try:
if Workspace.check_workspace_exists(node_name):
node_info = Workspace.get_node_info_in_workspace(node_name)
else:
node_info = nm.get_node_info(node_name)
node = model.CNode(node_info)
self._node_preinit(node)
except InfraSimError, e:
print e.value
logger_cmd.error("cmd res: {}".format(e.value))
return
示例4: test_start_status_restart_status_destroy_status
def test_start_status_restart_status_destroy_status(self):
"""
CLI test: start, restart and destroy a node and check status respectively
"""
output_status = {}
output_start = run_command("infrasim node start")
self.assertEqual(output_start[0], 0)
self.assertTrue(Workspace.check_workspace_exists(self.node_name))
output_status["start"] = run_command("infrasim node status")
self.assertEqual(output_status["start"][0], 0)
output_restart = run_command("infrasim node restart")
self.assertEqual(output_restart[0], 0)
self.assertTrue(Workspace.check_workspace_exists(self.node_name))
output_status["restart"] = run_command("infrasim node status")
self.assertEqual(output_status["restart"][0], 0)
output_destroy = run_command("infrasim node destroy")
self.assertEqual(output_destroy[0], 0)
self.assertFalse(Workspace.check_workspace_exists(self.node_name))
output_status["destroy"] = run_command("infrasim node status")
self.assertEqual(output_status["destroy"][0], 0)
assert "{}-socat is running".format(self.node_name) in output_start[1]
assert "{}-bmc is running".format(self.node_name) in output_start[1]
assert "{}-node is running".format(self.node_name) in output_start[1]
assert "{}-socat is running".format(self.node_name) in output_status["start"][1]
assert "{}-bmc is running".format(self.node_name) in output_status["start"][1]
assert "{}-node is running".format(self.node_name) in output_status["start"][1]
assert "{}-socat is stopped".format(self.node_name) in output_restart[1]
assert "{}-bmc is stopped".format(self.node_name) in output_restart[1]
assert "{}-node is stopped".format(self.node_name) in output_restart[1]
assert "{}-socat is running".format(self.node_name) in output_restart[1]
assert "{}-bmc is running".format(self.node_name) in output_restart[1]
assert "{}-node is running".format(self.node_name) in output_restart[1]
assert "{}-socat is running".format(self.node_name) in output_status["restart"][1]
assert "{}-bmc is running".format(self.node_name) in output_status["restart"][1]
assert "{}-node is running".format(self.node_name) in output_status["restart"][1]
assert "Node {} runtime workspace is destroyed".format(self.node_name) in output_destroy[1]
assert "Node {} runtime workspace doesn't exist".format(self.node_name) in output_status["destroy"][1]
示例5: init
def init(self):
node = get_dir_list(infrasim_home)
# remove the file whose name starts from "."
for nd in node:
if nd[0] is not '.' and Workspace.check_node(nd):
nd_status = NodeStatus(nd)
self.__node_list.append(nd_status)
示例6: check_node_start_workspace
def check_node_start_workspace(node_name):
conf = Workspace.get_node_info_in_workspace(node_name)
node_root = os.path.join(config.infrasim_home, conf["name"])
# Check node data folder and files exist
node_type = conf["type"]
data_folder = os.path.join(node_root, "data")
node_emu = os.path.join(data_folder, "{}.emu".format(node_type))
node_bios = os.path.join(data_folder, "{}_smbios.bin".format(node_type))
assert os.path.exists(data_folder) is True
assert os.path.exists(node_emu) is True
assert os.path.exists(node_bios) is True
# Check node script folder and files exist
script_folder = os.path.join(node_root, "scripts")
script_chassiscontrol = os.path.join(script_folder, "chassiscontrol")
script_lancontrol = os.path.join(script_folder, "lancontrol")
script_startcmd = os.path.join(script_folder, "startcmd")
script_stopcmd = os.path.join(script_folder, "stopcmd")
script_resetcmd = os.path.join(script_folder, "resetcmd")
assert os.path.exists(script_folder) is True
assert os.path.exists(script_chassiscontrol) is True
assert os.path.exists(script_lancontrol) is True
assert os.path.exists(script_startcmd) is True
assert os.path.exists(script_stopcmd) is True
assert os.path.exists(script_resetcmd) is True
# Check etc folder and files exist
etc_folder = os.path.join(node_root, "etc")
etc_infrasim_yml = os.path.join(etc_folder, "infrasim.yml")
etc_vbmc_conf = os.path.join(etc_folder, "vbmc.conf")
assert os.path.exists(etc_folder) is True
assert os.path.exists(etc_infrasim_yml) is True
assert os.path.exists(etc_vbmc_conf) is True
# Check disk image exist
node_name = conf["name"]
node_drive = conf['compute']['storage_backend'][0]['drives']
# set drive 'file'
for i in range(1, len(node_drive) + 1):
disk_file = os.path.join(node_root, "sd{0}.img".format(chr(96 + i)))
assert os.path.exists(disk_file) is True
# Check serial device exist
serial_dev = os.path.join(node_root, ".pty0_{}".format(node_name))
assert os.path.exists(serial_dev) is True
# Check unix socket file
serial = os.path.join(node_root, ".serial")
assert os.path.exists(serial) is True
# Check node runtime pid file exist
node_socat = os.path.join(node_root, ".{}-socat.pid".format(node_name))
node_ipmi = os.path.join(node_root, ".{}-bmc.pid".format(node_name))
node_qemu = os.path.join(node_root, ".{}-node.pid".format(node_name))
assert os.path.exists(node_socat) is True
assert os.path.exists(node_ipmi) is True
assert os.path.exists(node_qemu) is True
示例7: test_init
def test_init(self):
"""
CLI test: test init "-f" which will remove existing workspace
"""
output_info = {}
output_start = run_command("infrasim node start")
self.assertEqual(output_start[0], 0)
self.assertTrue(Workspace.check_workspace_exists(self.node_name))
output_info['start'] = run_command("infrasim node info")
self.assertEqual(output_info['start'][0], 0)
self.assertRaises(CommandRunFailed, run_command,
cmd="infrasim init -s", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
run_command("infrasim init -s -f")
self.assertEqual(len(os.listdir(config.infrasim_home)), 1)
# Verify if it will reinstall packages when user confirmed 'Y'
result = run_command_with_user_input("infrasim init", True, subprocess.PIPE, subprocess.PIPE, subprocess.PIPE, "Y\nY\nY\n")
assert "downloading Infrasim_Qemu" in result[1]
assert "downloading OpenIpmi" in result[1]
assert "downloading Seabios" in result[1]
result = run_command_with_user_input("infrasim init", True, subprocess.PIPE, subprocess.PIPE, subprocess.PIPE, "Y\nyes\nn\n")
assert "downloading Infrasim_Qemu" in result[1]
assert "downloading OpenIpmi" in result[1]
assert "downloading Seabios" not in result[1]
result = run_command_with_user_input("infrasim init", True, subprocess.PIPE, subprocess.PIPE, subprocess.PIPE, "no\nN\nY\n")
assert "downloading Infrasim_Qemu" not in result[1]
assert "downloading OpenIpmi" not in result[1]
assert "downloading Seabios" in result[1]
示例8: test_start_destroy
def test_start_destroy(self):
"""
CLI test: start, then destroy the node directly
"""
output_start = run_command("infrasim node start")
self.assertEqual(output_start[0], 0)
self.assertTrue(Workspace.check_workspace_exists(self.node_name))
output_destroy = run_command("infrasim node destroy")
self.assertEqual(output_destroy[0], 0)
self.assertFalse(Workspace.check_workspace_exists(self.node_name))
assert "{}-socat is running".format(self.node_name) in output_start[1]
assert "{}-bmc is running".format(self.node_name) in output_start[1]
assert "{}-node is running".format(self.node_name) in output_start[1]
assert "Node {} runtime workspace is destroyed".format(self.node_name) in output_destroy[1]
示例9: test_destory_destroy
def test_destory_destroy(self):
"""
CLI test: fail to destroy a destroyed node
"""
output_start = run_command("infrasim node start")
self.assertEqual(output_start[0], 0)
self.assertTrue(Workspace.check_workspace_exists(self.node_name))
output_destroy_1 = run_command("infrasim node destroy")
self.assertEqual(output_destroy_1[0], 0)
self.assertFalse(Workspace.check_workspace_exists(self.node_name))
output_destroy_2 = run_command("infrasim node destroy")
self.assertEqual(output_destroy_2[0], 0)
self.assertFalse(Workspace.check_workspace_exists(self.node_name))
assert "Node {} runtime workspace is destroyed".format(self.node_name) in output_destroy_1[1]
assert "Node {} runtime workspace is not found".format(self.node_name) in output_destroy_2[1]
示例10: test_start_start
def test_start_start(self):
"""
CLI test: start a started node will hint it's running
"""
output_start_1 = run_command("infrasim node start")
self.assertEqual(output_start_1[0], 0)
self.assertTrue(Workspace.check_workspace_exists(self.node_name))
output_start_2 = run_command("infrasim node start")
self.assertEqual(output_start_2[0], 0)
self.assertTrue(Workspace.check_workspace_exists(self.node_name))
assert "{}-socat starts to run".format(self.node_name) in output_start_1[1]
assert "{}-bmc starts to run".format(self.node_name) in output_start_1[1]
assert "{}-node is running".format(self.node_name) in output_start_1[1]
assert "{}-socat is already running".format(self.node_name) in output_start_2[1]
assert "{}-bmc is already running".format(self.node_name) in output_start_2[1]
assert "{}-node is running".format(self.node_name) in output_start_2[1]
示例11: status
def status(self, node_name):
try:
node_info = Workspace.get_node_info_in_workspace(node_name)
node = model.CNode(node_info)
self._node_preinit(node, ignore_check=True)
node.status()
logger_cmd.info("cmd res: get node {} status OK".format(node_name))
except InfraSimError, e:
print e.value
logger_cmd.error("cmd res: {}".format(e.value))
示例12: destroy_existing_nodes
def destroy_existing_nodes():
nodes = os.listdir(config.infrasim_home)
if os.path.exists(config.infrasim_node_config_map):
nodes.remove('.node_map')
if os.path.exists(config.infrasim_chassis_config_map):
nodes.remove('.chassis_map')
for node in nodes:
if Workspace.check_node(node):
os.system("infrasim node destroy {}".format(node))
else:
os.system("infrasim chassis destroy {}".format(node))
示例13: test_start_info_destroy_info
def test_start_info_destroy_info(self):
"""
CLI test: start and destroy a node, and get node_info respectively
"""
output_info = {}
output_start = run_command("infrasim node start")
self.assertEqual(output_start[0], 0)
self.assertTrue(Workspace.check_workspace_exists(self.node_name))
output_info['start'] = run_command("infrasim node info")
self.assertEqual(output_info['start'][0], 0)
output_destroy = run_command("infrasim node destroy")
self.assertEqual(output_destroy[0], 0)
self.assertFalse(Workspace.check_workspace_exists(self.node_name))
output_info['destroy'] = run_command("infrasim node info")
self.assertEqual(output_info['destroy'][0], 0)
assert "{}-socat is running".format(self.node_name) in output_start[1]
assert "{}-bmc is running".format(self.node_name) in output_start[1]
assert "{}-node is running".format(self.node_name) in output_start[1]
assert "node name: {}".format(self.node_name) in output_info['start'][1]
assert "type:" in output_info['start'][1]
assert "memory size:" in output_info['start'][1]
assert "sol_enable:" in output_info['start'][1]
assert "cpu quantities:" in output_info['start'][1]
assert "cpu type:" in output_info['start'][1]
assert "network(s):" in output_info['start'][1]
assert "device" in output_info['start'][1]
assert "mode" in output_info['start'][1]
assert "name " in output_info['start'][1]
assert "storage backend:" in output_info['start'][1]
assert "type " in output_info['start'][1]
assert "max drive" in output_info['start'][1]
assert "drive size" in output_info['start'][1]
assert "Node {} runtime workspace is destroyed".format(self.node_name) in output_destroy[1]
assert "Node {} runtime workspace doesn't exist".format(self.node_name) in output_info['destroy'][1]
示例14: get_node_status
def get_node_status(self):
self.__node_info = Workspace.get_node_info_in_workspace(self.__node_name)
self.netns = self.__node_info.get("namespace", None)
base_path = os.path.join(infrasim_home, self.__node_name)
task_name = ['socat', 'bmc', 'node', 'racadm', 'ipmi_console']
task_list = {}
for task in task_name:
if task is 'ipmi_console':
pid_file = os.path.join(base_path, '.ipmi_console.pid')
else:
pid_file = os.path.join(base_path, ".{}-{}.pid".format(self.__node_name, task))
if os.path.exists(pid_file):
task_pid = get_task_pid(pid_file)
if not os.path.exists("/proc/{}".format(task_pid)):
os.remove(pid_file)
elif task_pid > 0:
task_list[task] = "{:<6}".format(task_pid)
return task_list
示例15: edit
def edit(self, node_name):
if node_name not in nm.get_name_list():
print "Fail to find node {0} configuration. It is not registered. Check by:\n" \
" infrasim config list".format(node_name)
logger_cmd.warning("cmd res: Fail to find node {0} configuration. It is not registered. Check by:\n"
" infrasim config list".format(node_name))
return
editor = os.environ.get('EDITOR', 'vi')
config_path = os.path.join(nm.get_mapping_folder(),
"{}.yml".format(node_name))
try:
os.system("{} {}".format(editor, config_path))
if Workspace.check_workspace_exists(node_name):
print "Warning: " \
"\033[93mPlease destroy node {}\033[0m " \
"before start or restart, " \
"or this edit won't work." .format(node_name)
logger_cmd.info("cmd res: edit node {} OK".format(node_name))
except OSError, e:
print e
logger_cmd.error("cmd res: {}".format(e))