本文整理汇总了Python中marvin.lib.utils.get_process_status函数的典型用法代码示例。如果您正苦于以下问题:Python get_process_status函数的具体用法?Python get_process_status怎么用?Python get_process_status使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_process_status函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stop_master_router
def stop_master_router(self, vpc):
self.logger.debug("Stopping Master Router of VPC '%s'...", vpc.name)
routers = list_routers(self.api_client, domainid=self.domain.id, account=self.account.name, vpcid=vpc.id)
for router in routers:
if router.redundantstate == 'MASTER':
cmd = stopRouter.stopRouterCmd()
cmd.id = router.id
# This will not fail-over gracefully and cause a ~3.6sec downtime
# cmd.forced = 'true'
self.api_client.stopRouter(cmd)
break
for router in routers:
if router.state == 'Running':
hosts = list_hosts(self.api_client, zoneid=router.zoneid, type='Routing', state='Up', id=router.hostid)
self.assertTrue(isinstance(hosts, list))
host = next(iter(hosts or []), None)
try:
host.user, host.passwd = get_host_credentials(self.config, host.name)
get_process_status(host.ipaddress, 22, host.user, host.passwd, router.linklocalip, "sh /opt/cosmic/router/scripts/checkrouter.sh ")
except KeyError as e:
raise Exception("Exception: %s" % e)
self.logger.debug("Master Router of VPC '%s' stopped", vpc.name)
示例2: test_01_single_VPC_iptables_policies
def test_01_single_VPC_iptables_policies(self):
""" Test iptables default INPUT/FORWARD policies on VPC router """
self.logger.debug("Starting test_01_single_VPC_iptables_policies")
routers = self.entity_manager.query_routers()
self.assertEqual(isinstance(routers, list), True, "Check for list routers response return valid data")
self.entity_manager.create_network(self.services["vpc_network_offering"], self.vpc.id, "10.1.1.1")
self.entity_manager.create_network(self.services["vpc_network_offering_no_lb"], self.vpc.id, "10.1.2.1")
self.entity_manager.add_nat_rules(self.vpc.id)
self.entity_manager.do_vpc_test()
for router in routers:
if not router.isredundantrouter and router.vpcid:
hosts = list_hosts(self.apiclient, id=router.hostid)
self.assertEqual(isinstance(hosts, list), True, "Check for list hosts response return valid data")
host = hosts[0]
host.user = self.hostConfig["username"]
host.passwd = self.hostConfig["password"]
host.port = self.services["configurableData"]["host"]["port"]
tables = [self.services["configurableData"]["input"], self.services["configurableData"]["forward"]]
for table in tables:
result = None
if self.hypervisor.lower() in ("vmware", "hyperv"):
result = get_process_status(
self.apiclient.connection.mgtSvr,
22,
self.apiclient.connection.user,
self.apiclient.connection.passwd,
router.linklocalip,
"iptables -L %s" % table,
hypervisor=self.hypervisor,
)
else:
try:
result = get_process_status(
host.ipaddress,
host.port,
host.user,
host.passwd,
router.linklocalip,
"iptables -L %s" % table,
)
except KeyError:
self.skipTest(
"Provide a marvin config file with host\
credentials to run %s"
% self._testMethodName
)
self.logger.debug("iptables -L %s: %s" % (table, result))
res = str(result)
self.assertEqual(res.count("DROP"), 1, "%s Default Policy should be DROP" % table)
示例3: check_routers_state
def check_routers_state(self,count=2, status_to_check="MASTER", expected_count=1, showall=False):
vals = ["MASTER", "BACKUP", "UNKNOWN"]
cnts = [0, 0, 0]
self.wait_for_vrrp()
result = "UNKNOWN"
self.query_routers(count, showall)
for router in self.routers:
if router.state == "Running":
hosts = list_hosts(
self.apiclient,
zoneid=router.zoneid,
type='Routing',
state='Up',
id=router.hostid
)
self.assertEqual(
isinstance(hosts, list),
True,
"Check list host returns a valid list"
)
host = hosts[0]
if self.hypervisor.lower() in ('vmware', 'hyperv'):
result = str(get_process_status(
self.apiclient.connection.mgtSvr,
22,
self.apiclient.connection.user,
self.apiclient.connection.passwd,
router.linklocalip,
"sh /opt/cloud/bin/checkrouter.sh ",
hypervisor=self.hypervisor
))
else:
try:
host.user, host.passwd = get_host_credentials(
self.config, host.ipaddress)
result = str(get_process_status(
host.ipaddress,
22,
host.user,
host.passwd,
router.linklocalip,
"sh /opt/cloud/bin/checkrouter.sh "
))
except KeyError:
self.skipTest(
"Marvin configuration has no host credentials to\
check router services")
if result.count(status_to_check) == 1:
cnts[vals.index(status_to_check)] += 1
if cnts[vals.index(status_to_check)] != expected_count:
self.fail("Expected '%s' routers at state '%s', but found '%s'!" % (expected_count, status_to_check, cnts[vals.index(status_to_check)]))
示例4: download_builtin_templates
def download_builtin_templates(apiclient, zoneid, hypervisor, host,
linklocalip, interval=60):
"""After setup wait till builtin templates are downloaded"""
# Change IPTABLES Rules
get_process_status(
host["ipaddress"],
host["port"],
host["username"],
host["password"],
linklocalip,
"iptables -P INPUT ACCEPT"
)
time.sleep(interval)
# Find the BUILTIN Templates for given Zone, Hypervisor
list_template_response = list_templates(
apiclient,
hypervisor=hypervisor,
zoneid=zoneid,
templatefilter='self'
)
if not isinstance(list_template_response, list):
raise Exception("Failed to download BUILTIN templates")
# Ensure all BUILTIN templates are downloaded
templateid = None
for template in list_template_response:
if template.templatetype == "BUILTIN":
templateid = template.id
# Sleep to ensure that template is in downloading state after adding
# Sec storage
time.sleep(interval)
while True:
template_response = list_templates(
apiclient,
id=templateid,
zoneid=zoneid,
templatefilter='self'
)
template = template_response[0]
# If template is ready,
# template.status = Download Complete
# Downloading - x% Downloaded
# Error - Any other string
if template.status == 'Download Complete':
break
elif 'Downloaded' in template.status:
time.sleep(interval)
elif 'Installing' not in template.status:
raise Exception("ErrorInDownload")
return
示例5: wait_vm_ready
def wait_vm_ready(self, router, vmip):
self.logger.debug("Check whether VM %s is up" % vmip)
max_tries = 15
test_tries = 0
ping_result = 0
host = self.get_host_details(router)
while test_tries < max_tries:
try:
ping_result = get_process_status(
host.ipaddress,
host.port,
host.user,
host.passwd,
router.linklocalip,
"ping -c 1 " + vmip + ">/dev/null; echo $?"
)
# Return value 0 means we were able to ping
if int(ping_result[0]) == 0:
self.logger.debug("VM %s is pingable, give it 10s to request the password" % vmip)
time.sleep(10)
return True
except KeyError:
self.skipTest("Provide a marvin config file with host credentials to run %s" % self._testMethodName)
self.logger.debug("Ping result from the Router on IP '%s' is -> '%s'" % (router.linklocalip, ping_result[0]))
test_tries += 1
self.logger.debug("Executing vm ping %s/%s" % (test_tries, max_tries))
time.sleep(5)
return False
示例6: test_dnsmasq_service_dhcp_dns_config
def test_dnsmasq_service_dhcp_dns_config(self, router, dns_server):
host = self.get_host_details(router)
nic = 'eth3'
# Get the dnsmasq config entry
command_to_execute = "grep '%s,6' /etc/dnsmasq.d/%s.conf" % (nic, nic)
dnsmasq_dns_config_result = ""
try:
dnsmasq_dns_config_result = get_process_status(
host.ipaddress,
host.port,
host.user,
host.passwd,
router.linklocalip,
command_to_execute)
except KeyError:
self.skipTest(
"Provide a marvin config file with host\
credentials to run %s" %
self._testMethodName)
command_result = str(dnsmasq_dns_config_result)
self.logger.debug("Got this response: %s " % command_result)
# Check to see if our VM is in the password file
if command_result.count(dns_server) == 0:
return False
return True
示例7: test_dhcphopts
def test_dhcphopts(self, ipaddress, router):
hosts = list_hosts(
self.apiclient,
id=router.hostid)
self.assertEqual(
isinstance(hosts, list),
True,
"Check for list hosts response return valid data")
host = hosts[0]
host.user = self.hostConfig['username']
host.passwd = self.hostConfig['password']
host.port = self.services["configurableData"]["host"]["port"]
host_tag = ipaddress.replace(".","_")
if self.hypervisor.lower() in ('vmware', 'hyperv'):
result = get_process_status(
self.apiclient.connection.mgtSvr,
22,
self.apiclient.connection.user,
self.apiclient.connection.passwd,
router.linklocalip,
"cat /etc/dhcpopts.txt | grep %s" % (host_tag),
hypervisor=self.hypervisor)
else:
try:
result = get_process_status(
host.ipaddress,
host.port,
host.user,
host.passwd,
router.linklocalip,
"cat /etc/dhcpopts.txt | grep %s" % (host_tag))
except KeyError:
self.skipTest(
"Provide a marvin config file with host\
credentials to run %s" %
self._testMethodName)
self.logger.debug("cat /etc/dhcpopts.txt | grep %s RESULT IS ==> %s" % (host_tag, result))
res = str(result)
self.assertNotEqual(
res.count(host_tag),
0,
"DHCP opts file does not contain exception for IP ==> %s!" % res)
示例8: test_password_file_not_empty
def test_password_file_not_empty(self, vm, router):
hosts = list_hosts(
self.apiclient,
id=router.hostid)
self.assertEqual(
isinstance(hosts, list),
True,
"Check for list hosts response return valid data")
host = hosts[0]
host.user = self.hostConfig['username']
host.passwd = self.hostConfig['password']
host.port = self.services["configurableData"]["host"]["port"]
if self.hypervisor.lower() in ('vmware', 'hyperv'):
result = get_process_status(
self.apiclient.connection.mgtSvr,
22,
self.apiclient.connection.user,
self.apiclient.connection.passwd,
router.linklocalip,
"cat /var/cache/cloud/passwords-%s | grep %s | sed 's/=/ /g' | awk '{print $1}'" % (vm.nic[0].gateway, vm.nic[0].ipaddress),
hypervisor=self.hypervisor
)
else:
try:
result = get_process_status(
host.ipaddress,
host.port,
host.user,
host.passwd,
router.linklocalip,
"cat /var/cache/cloud/passwords-%s | grep %s | sed 's/=/ /g' | awk '{print $1}'" % (vm.nic[0].gateway, vm.nic[0].ipaddress))
except KeyError:
self.skipTest(
"Provide a marvin config file with host\
credentials to run %s" %
self._testMethodName)
self.logger.debug("cat /var/cache/cloud/passwords-%s | grep %s | sed 's/=/ /g' | awk '{print $1}' RESULT IS ==> %s" % (vm.nic[0].gateway, vm.nic[0].ipaddress, result))
res = str(result)
self.assertEqual(
res.count(vm.nic[0].ipaddress),
1,
"Password file is empty or doesn't exist!")
示例9: test_dhcphosts
def test_dhcphosts(self, vm, router):
hosts = list_hosts(
self.apiclient,
id=router.hostid)
self.assertEqual(
isinstance(hosts, list),
True,
"Check for list hosts response return valid data")
host = hosts[0]
host.user = self.hostConfig['username']
host.passwd = self.hostConfig['password']
host.port = self.services["configurableData"]["host"]["port"]
if self.hypervisor.lower() in ('vmware', 'hyperv'):
result = get_process_status(
self.apiclient.connection.mgtSvr,
22,
self.apiclient.connection.user,
self.apiclient.connection.passwd,
router.linklocalip,
"cat /etc/dhcphosts.txt | grep %s | sed 's/\,/ /g' | awk '{print $2}'" % (vm.nic[0].ipaddress),
hypervisor=self.hypervisor)
else:
try:
result = get_process_status(
host.ipaddress,
host.port,
host.user,
host.passwd,
router.linklocalip,
"cat /etc/dhcphosts.txt | grep %s | sed 's/\,/ /g' | awk '{print $2}'" % (vm.nic[0].ipaddress))
except KeyError:
self.skipTest(
"Provide a marvin config file with host\
credentials to run %s" %
self._testMethodName)
self.logger.debug("cat /etc/dhcphosts.txt | grep %s | sed 's/\,/ /g' | awk '{print $2}' RESULT IS ==> %s" % (vm.nic[0].ipaddress, result))
res = str(result)
self.assertEqual(
res.count(vm.nic[0].ipaddress),
1,
"DHCP hosts file contains duplicate IPs ==> %s!" % res)
示例10: test_01_routervm_iptables_policies
def test_01_routervm_iptables_policies(self):
""" Test iptables default INPUT/FORWARD policy on RouterVM """
self.logger.debug("Starting test_01_routervm_iptables_policies")
vm1 = self.entity_manager.deployvm()
routers = self.entity_manager.query_routers()
self.assertEqual(
isinstance(routers, list), True,
"Check for list routers response return valid data")
for router in routers:
if not router.isredundantrouter and not router.vpcid:
hosts = list_hosts(
self.apiclient,
id=router.hostid)
self.assertEqual(
isinstance(hosts, list),
True,
"Check for list hosts response return valid data")
host = hosts[0]
host.user = self.services["configurableData"]["host"]["username"]
host.passwd = self.services["configurableData"]["host"]["password"]
host.port = self.services["configurableData"]["host"]["port"]
tables = [self.services["configurableData"]["input"], self.services["configurableData"]["forward"]]
for table in tables:
try:
result = get_process_status(
host.ipaddress,
host.port,
host.user,
host.passwd,
router.linklocalip,
'iptables -L %s' % table)
except KeyError:
self.skipTest(
"Provide a marvin config file with host\
credentials to run %s" %
self._testMethodName)
self.logger.debug("iptables -L %s: %s" % (table, result))
res = str(result)
self.assertEqual(
res.count("policy DROP"),
1,
"%s Default Policy should be DROP" % table)
示例11: getCommandResultFromRouter
def getCommandResultFromRouter(self, router, command):
"""Run given command on router and return the result"""
if (self.hypervisor.lower() == 'vmware'
or self.hypervisor.lower() == 'hyperv'):
result = get_process_status(
self.apiclient.connection.mgtSvr,
22,
self.apiclient.connection.user,
self.apiclient.connection.passwd,
router.linklocalip,
command,
hypervisor=self.hypervisor
)
else:
hosts = list_hosts(
self.apiclient,
id=router.hostid,
)
self.assertEqual(
isinstance(hosts, list),
True,
"Check for list hosts response return valid data"
)
host = hosts[0]
host.user = self.services["configurableData"]["host"]["username"]
host.passwd = self.services["configurableData"]["host"]["password"]
result = get_process_status(
host.ipaddress,
22,
host.user,
host.passwd,
router.linklocalip,
command
)
return result
示例12: get_router_state
def get_router_state(self, router):
host = self.get_host_details(router)
router_state = "UNKNOWN"
try:
router_state = get_process_status(
host.ipaddress,
host.port,
host.user,
host.passwd,
router.linklocalip,
"/opt/cosmic/router/scripts/checkrouter.sh | cut -d\" \" -f2"
)
except:
self.logger.debug("Oops, unable to determine redundant state for router with link local address %s" % (router.linklocalip))
pass
self.logger.debug("The router with link local address %s reports state %s" % (router.linklocalip, router_state))
return router_state[0]
示例13: check_routers_interface
def check_routers_interface(self,count=2, interface_to_check="eth1", expected_exists=True, showall=False):
result = ""
self.query_routers(count, showall)
for router in self.routers:
if router.state == "Running":
hosts = list_hosts(
self.apiclient,
zoneid=router.zoneid,
type='Routing',
state='Up',
id=router.hostid
)
self.assertEqual(
isinstance(hosts, list),
True,
"Check list host returns a valid list"
)
host = hosts[0]
try:
host.user, host.passwd = get_host_credentials(self.config, host.ipaddress)
result = str(get_process_status(
host.ipaddress,
22,
host.user,
host.passwd,
router.linklocalip,
"ip a | grep %s | grep state | awk '{print $9;}'" % interface_to_check
))
except KeyError:
self.skipTest("Marvin configuration has no host credentials to check router services")
if expected_exists:
if (result.count("UP") == 1) or (result.count("DOWN") == 1):
self.logger.debug("Expected interface '%s' to exist and it does!" % interface_to_check)
else:
self.fail("Expected interface '%s' to exist, but it didn't!" % interface_to_check)
else:
if (result.count("UP") == 1) or (result.count("DOWN") == 1):
self.fail("Expected interface '%s' to not exist, but it did!" % interface_to_check)
else:
self.logger.debug("Expected interface '%s' to not exist, and it didn't!" % interface_to_check)
示例14: test_password_server_logs
def test_password_server_logs(self, vm, router):
host = self.get_host_details(router)
router_state = self.get_router_state(router)
if router.isredundantrouter and router_state != "MASTER":
print "Found router in non-MASTER state '" + router.redundantstate + "' so skipping test."
return True
# Get the related passwd server logs for our vm
command_to_execute = "grep %s /var/log/messages" % vm.nic[0].ipaddress
password_log_result = ""
try:
password_log_result = get_process_status(
host.ipaddress,
host.port,
host.user,
host.passwd,
router.linklocalip,
command_to_execute)
except KeyError:
self.skipTest(
"Provide a marvin config file with host\
credentials to run %s" %
self._testMethodName)
command_result = str(password_log_result)
self.logger.debug("Got this response: %s " % command_result)
# Check to see if our VM is in the password file
if command_result.count("password saved for VM IP") == 0:
return False
# Check if the password was retrieved from the passwd server. If it is, the actual password is replaced with 'saved_password'
if command_result.count("password sent to") == 0:
return False
return True
示例15: test_process_running
def test_process_running(self, find_process, router):
host = self.get_host_details(router)
number_of_processes_found = 0
try:
number_of_processes_found = get_process_status(
host.ipaddress,
host.port,
host.user,
host.passwd,
router.linklocalip,
"ps aux | grep " + find_process + " | grep -v grep | wc -l"
)
except KeyError:
self.skipTest("Provide a marvin config file with host credentials to run %s" % self._testMethodName)
self.logger.debug("Result from the Router on IP '%s' is -> Number of processess found: '%s'" % (router.linklocalip, number_of_processes_found[0]))
expected_nr_or_processes = 1
self.assertEqual(int(number_of_processes_found[0]), expected_nr_or_processes,
msg="Router should have " + str(expected_nr_or_processes) + " '" + find_process + "' processes running, found " + str(number_of_processes_found[0]))