本文整理匯總了Python中fuelweb_test.models.nailgun_client.NailgunClient類的典型用法代碼示例。如果您正苦於以下問題:Python NailgunClient類的具體用法?Python NailgunClient怎麽用?Python NailgunClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了NailgunClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run_ostf
def run_ostf(admin_node_ip, env_name, log):
client = NailgunClient(admin_node_ip)
cluster_id = client.get_cluster_id(env_name)
env = load_env(env_name)
result = ostf_run(log, client, cluster_id, env.ostf_test_sets, env.ostf_should_fail, env.ostf_timeout)
return result
示例2: make_snapshot
def make_snapshot (admin_node_ip):
client = NailgunClient(admin_node_ip)
task = client.generate_logs()
result = task_wait(client, task, 600, 10)
if result['status'] == 'ready':
return "OK"
else:
return result['message']
示例3: deploy_cluster
def deploy_cluster(admin_node_ip, env_name):
client = NailgunClient(admin_node_ip)
cluster_id = client.get_cluster_id(env_name)
env = load_env(env_name)
task = client.deploy_cluster_changes(cluster_id)
result = task_wait(client, task, env.deploy_timeout, 30)
if result['status'] == 'ready':
return "OK"
else:
return result['message']
示例4: verify_network
def verify_network(admin_node_ip, env_name):
client = NailgunClient(admin_node_ip)
cluster_id = client.get_cluster_id(env_name)
env = load_env(env_name)
task = client.verify_networks(cluster_id, client.get_networks(cluster_id)['networks'])
result = task_wait(client, task, 300, 10)
if result['status'] == 'ready':
return "OK"
else:
return result['message']
示例5: provision_cluster_separately
def provision_cluster_separately(admin_node_ip, env_name):
client = NailgunClient(admin_node_ip)
cluster_id = client.get_cluster_id(env_name)
env = load_env(env_name)
# separate provisioning, useful on virtual envs since provisioning runs much faster this way
cluster_nodes = client.list_cluster_nodes(cluster_id)
for cur_node in cluster_nodes:
task = client.provision_node(cluster_id, cur_node['id'])
result = task_wait(client, task, 3600, 60)
if result['status'] != 'ready':
return result['message']
return "OK"
示例6: provision_cluster
def provision_cluster(admin_node_ip, env_name):
client = NailgunClient(admin_node_ip)
cluster_id = client.get_cluster_id(env_name)
env = load_env(env_name)
all_nodes_ids = ""
# separate provisioning, useful on virtual envs since provisioning runs much faster this way
cluster_nodes = client.list_cluster_nodes(cluster_id)
for cur_node in cluster_nodes:
if all_nodes_ids == "":
all_nodes_ids = str(cur_node['id'])
else:
all_nodes_ids = all_nodes_ids + "," + str(cur_node['id'])
# provision all nodes
task = client.provision_node(cluster_id, all_nodes_ids)
result = task_wait(client, task, env.deploy_timeout, 30)
if result['status'] == 'ready':
return "OK"
else:
return result['message']
示例7: remove_env
def remove_env(admin_node_ip, env_name, dont_wait_for_nodes=True):
LOG.info('Removing cluster with name:{0}'.format(env_name))
client = NailgunClient(admin_node_ip)
cluster_id = client.get_cluster_id(env_name)
all_nodes = []
if cluster_id:
cluster_nodes = client.list_cluster_nodes(cluster_id)
if len(cluster_nodes) > 0:
all_nodes = client.list_nodes()
client.delete_cluster(cluster_id)
else:
LOG.info('Looks like cluster has not been created before.Okay')
return "OK"
# wait for cluster to disappear
rerty_c = 120
for i in range(rerty_c):
cluster_id = client.get_cluster_id(env_name)
LOG.info('Wait for cluster to disappear...try %s /%s' % (i, rerty_c))
if cluster_id:
time.sleep(10)
else:
break
# fail if cluster is still around
if cluster_id:
return "Can't delete cluster"
# wait for removed nodes to come back online
if not dont_wait_for_nodes:
for i in range(90):
cur_nodes = client.list_nodes()
if len(cur_nodes) < len(all_nodes):
LOG.info('Wait for nodes to came back. Should be:{0} '
'Currently:{1} ...try {2}'.format(
len(all_nodes), len(cur_nodes), i))
time.sleep(10)
if len(client.list_nodes()) < len(all_nodes) and not dont_wait_for_nodes:
return "Timeout while waiting for removed nodes ({}) to come back up".format(
len(cluster_nodes))
return "OK"
示例8: remove_env
def remove_env(admin_node_ip, env_name, dont_wait_for_nodes):
client = NailgunClient(admin_node_ip)
cluster_id = client.get_cluster_id(env_name)
need_to_wait_for_nodes = False
all_nodes = []
if cluster_id:
cluster_nodes = client.list_cluster_nodes(cluster_id)
if len(cluster_nodes) > 0:
need_to_wait_for_nodes = True
all_nodes = client.list_nodes()
client.delete_cluster(cluster_id)
else:
return "OK"
# wait for cluster to disappear
for i in range(60):
cluster_id = client.get_cluster_id(env_name)
if cluster_id:
time.sleep(10)
# fail if cluster is still around
if cluster_id:
return "Can't delete cluster"
# wait for removed nodes to come back online
if not dont_wait_for_nodes:
for i in range(90):
cur_nodes = client.list_nodes()
if len(cur_nodes) < len(all_nodes):
time.sleep(10)
if len(cur_nodes) < len(all_nodes) and not dont_wait_for_nodes:
return "Timeout while waiting for removed nodes ({}) to come back up".format(len(cluster_nodes))
return "OK"
示例9: __init__
def __init__(self, admin_node_ip, environment):
self.admin_node_ip = admin_node_ip
self.client = NailgunClient(admin_node_ip)
self._environment = environment
super(FuelWebClient, self).__init__()
示例10: FuelWebClient
class FuelWebClient(object):
def __init__(self, admin_node_ip, environment):
self.admin_node_ip = admin_node_ip
self.client = NailgunClient(admin_node_ip)
self._environment = environment
super(FuelWebClient, self).__init__()
@property
def environment(self):
"""Environment Model
:rtype: EnvironmentModel
"""
return self._environment
@staticmethod
@logwrap
def get_cluster_status(ssh_remote, smiles_count, networks_count=1):
checkers.verify_service_list(ssh_remote, smiles_count)
checkers.verify_glance_index(ssh_remote)
checkers.verify_network_list(networks_count, ssh_remote)
@logwrap
def _ostf_test_wait(self, cluster_id, timeout):
wait(
lambda: all([run["status"] == "finished" for run in self.client.get_ostf_test_run(cluster_id)]),
timeout=timeout,
)
return self.client.get_ostf_test_run(cluster_id)
@logwrap
def _tasks_wait(self, tasks, timeout):
return [self.task_wait(task, timeout) for task in tasks]
@logwrap
def add_syslog_server(self, cluster_id, host, port):
self.client.add_syslog_server(cluster_id, host, port)
@logwrap
def assert_cluster_floating_list(self, node_name, expected_ips):
current_ips = self.get_cluster_floating_list(node_name)
assert_equal(set(expected_ips), set(current_ips))
@logwrap
def assert_cluster_ready(self, node_name, smiles_count, networks_count=1, timeout=300):
remote = self.environment.get_ssh_to_remote(
self.get_nailgun_node_by_devops_node(self.environment.get_virtual_environment().node_by_name(node_name))[
"ip"
]
)
_wait(
lambda: self.get_cluster_status(remote, smiles_count=smiles_count, networks_count=networks_count),
timeout=timeout,
)
@logwrap
def assert_ostf_run_certain(self, cluster_id, tests_must_be_passed, timeout=10 * 60):
set_result_list = self._ostf_test_wait(cluster_id, timeout)
tests_pass_count = 0
tests_count = len(tests_must_be_passed)
result = False
for set_result in set_result_list:
success = [test for test in set_result["tests"] if test["status"] == "success"]
for test_id in success:
for test_class in tests_must_be_passed:
if test_id["id"].find(test_class) > -1:
tests_pass_count += 1
logger.debug("Passed OSTF test {} found".format(test_class))
if tests_pass_count == tests_count:
result = True
assert_true(result)
@logwrap
def assert_ostf_run(self, cluster_id, should_fail=0, failed_test_name=None, timeout=15 * 60):
set_result_list = self._ostf_test_wait(cluster_id, timeout)
failed_tests_res = []
failed = 0
actual_failed_names = []
test_result = {}
for set_result in set_result_list:
failed += len(
filter(lambda test: test["status"] == "failure" or test["status"] == "error", set_result["tests"])
)
[actual_failed_names.append(test["name"]) for test in set_result["tests"] if test["status"] != "success"]
[test_result.update({test["name"]: test["status"]}) for test in set_result["tests"]]
[
failed_tests_res.append({test["name"]: test["message"]})
for test in set_result["tests"]
if test["status"] != "success"
]
logger.info("OSTF test statuses are : {0}".format(test_result))
if failed_test_name:
for test_name in failed_test_name:
assert_true(
#.........這裏部分代碼省略.........
示例11: FuelWebClient
class FuelWebClient(object):
def __init__(self, admin_node_ip, environment):
self.admin_node_ip = admin_node_ip
self.client = NailgunClient(admin_node_ip)
self._environment = environment
super(FuelWebClient, self).__init__()
@property
def environment(self):
"""
:rtype: EnvironmentModel
"""
return self._environment
@staticmethod
@logwrap
def get_cluster_status(ssh_remote, smiles_count, networks_count=1):
verify_service_list(ssh_remote, smiles_count)
verify_glance_index(ssh_remote)
verify_network_list(networks_count, ssh_remote)
@logwrap
def _ostf_test_wait(self, cluster_id, timeout):
wait(
lambda: all([run['status'] == 'finished'
for run in
self.client.get_ostf_test_run(cluster_id)]),
timeout=timeout)
return self.client.get_ostf_test_run(cluster_id)
@logwrap
def _tasks_wait(self, tasks, timeout):
return [self.task_wait(task, timeout) for task in tasks]
@logwrap
def add_syslog_server(self, cluster_id, host, port):
self.client.add_syslog_server(cluster_id, host, port)
@logwrap
def assert_cluster_floating_list(self, node_name, expected_ips):
current_ips = self.get_cluster_floating_list(node_name)
assert_equal(set(expected_ips), set(current_ips))
@logwrap
def assert_cluster_ready(self, node_name, smiles_count,
networks_count=1, timeout=300):
remote = self.environment.get_ssh_to_remote(
self.get_nailgun_node_by_devops_node(
self.environment.get_virtual_environment().
node_by_name(node_name))['ip']
)
_wait(
lambda: self.get_cluster_status(
remote,
smiles_count=smiles_count,
networks_count=networks_count),
timeout=timeout)
@logwrap
def assert_ostf_run(self, cluster_id, should_fail=0, should_pass=0,
timeout=10 * 60):
set_result_list = self._ostf_test_wait(cluster_id, timeout)
passed = 0
failed = 0
for set_result in set_result_list:
passed += len(filter(lambda test: test['status'] == 'success',
set_result['tests']))
failed += len(
filter(
lambda test: test['status'] == 'failure' or
test['status'] == 'error',
set_result['tests']
)
)
assert_true(
passed >= should_pass, 'Passed tests, pass: {} should pass: {}'
''.format(passed, should_pass))
assert_true(
failed <= should_fail, 'Failed tests, fails: {} should fail: {}'
''.format(failed, should_fail))
def assert_release_state(self, release_name, state='available'):
for release in self.client.get_releases():
if release["name"].find(release_name) != -1:
assert_equal(release['state'], state)
return release["id"]
@logwrap
def assert_task_success(self, task, timeout=110 * 60, interval=5):
task = self.task_wait(task, timeout, interval)
assert_equal(
task['status'], 'ready',
"Task '{name}' has incorrect status. {} != {}".format(
task['status'], 'ready', name=task["name"]
)
)
#.........這裏部分代碼省略.........
示例12: debug
pprinter = pprint.PrettyPrinter(indent=1, width=80, depth=None)
# Input params:
CLUSTER_CONFIG = os.environ.get("CLUSTER_CONFIG", "test_lab.yaml")
# optional
START_DEPLOYMENT = os.environ.get("START_DEPLOYMENT", "false")
UPLOAD_DEPLOYMENT_INFO = os.environ.get("UPLOAD_DEPLOYMENT_INFO", "false")
IPMI_CONFIGS = os.environ.get("IPMI_CONFIGS", "ipmi/netifnames.yaml")
# debug (don't use it!)
test_mode = False
LOG.info('Try load: %s' % (CLUSTER_CONFIG))
lab_config = yaml.load(open(CLUSTER_CONFIG))
client = NailgunClient(lab_config["fuel-master"])
##################################
# versions workaround
f_release = client.get_api_version()['release']
LOG.info('Fuel-version: \n%s' % pprinter.pformat(client.get_api_version()))
if float(f_release[:3]) < 6:
api_cluster_id = "cluster_id"
else:
api_cluster_id = "cluster"
###################################
def fetch_hw_data(config_yaml=IPMI_CONFIGS):
"""
:param IPMI_CONFIGS:
示例13: FuelWebClient
class FuelWebClient(object):
def __init__(self, admin_node_ip, environment):
self.admin_node_ip = admin_node_ip
self.client = NailgunClient(admin_node_ip)
self._environment = environment
super(FuelWebClient, self).__init__()
@property
def environment(self):
"""Environment Model
:rtype: EnvironmentModel
"""
return self._environment
@staticmethod
@logwrap
def get_cluster_status(ssh_remote, smiles_count, networks_count=1):
checkers.verify_service_list(ssh_remote, smiles_count)
checkers.verify_glance_index(ssh_remote)
checkers.verify_network_list(networks_count, ssh_remote)
@logwrap
def _ostf_test_wait(self, cluster_id, timeout):
logger.info('Wait OSTF tests at cluster #%s for %s seconds',
cluster_id, timeout)
wait(
lambda: all([run['status'] == 'finished'
for run in
self.client.get_ostf_test_run(cluster_id)]),
timeout=timeout)
return self.client.get_ostf_test_run(cluster_id)
@logwrap
def _tasks_wait(self, tasks, timeout):
return [self.task_wait(task, timeout) for task in tasks]
@logwrap
def add_syslog_server(self, cluster_id, host, port):
logger.info('Add syslog server %s:%s to cluster #%s',
host, port, cluster_id)
self.client.add_syslog_server(cluster_id, host, port)
@logwrap
def assert_cluster_floating_list(self, node_name, expected_ips):
logger.info('Assert floating IPs at node %s. Expected %s',
node_name, expected_ips)
current_ips = self.get_cluster_floating_list(node_name)
assert_equal(set(expected_ips), set(current_ips),
'Current floating IPs {0}'.format(current_ips))
@logwrap
def assert_cluster_ready(self, node_name, smiles_count,
networks_count=1, timeout=300):
logger.info('Assert cluster services are UP')
remote = self.environment.get_ssh_to_remote(
self.get_nailgun_node_by_devops_node(
self.environment.get_virtual_environment().
node_by_name(node_name))['ip']
)
_wait(
lambda: self.get_cluster_status(
remote,
smiles_count=smiles_count,
networks_count=networks_count),
timeout=timeout)
@logwrap
def assert_ostf_run_certain(self, cluster_id, tests_must_be_passed,
timeout=10 * 60):
logger.info('Assert OSTF tests are passed at cluster #%s: %s',
cluster_id, tests_must_be_passed)
set_result_list = self._ostf_test_wait(cluster_id, timeout)
tests_pass_count = 0
tests_count = len(tests_must_be_passed)
result = False
for set_result in set_result_list:
success = [test for test in set_result['tests']
if test['status'] == 'success']
for test_id in success:
for test_class in tests_must_be_passed:
if test_id['id'].find(test_class) > -1:
tests_pass_count += 1
logger.info('Passed OSTF tests %s found', test_class)
if tests_pass_count == tests_count:
result = True
assert_true(result)
@logwrap
def assert_ostf_run(self, cluster_id, should_fail=0,
failed_test_name=None, timeout=15 * 60):
logger.info('Assert OSTF run at cluster #%s. '
'Should fail %s tests named %s',
cluster_id, should_fail, failed_test_name)
set_result_list = self._ostf_test_wait(cluster_id, timeout)
failed_tests_res = []
failed = 0
actual_failed_names = []
test_result = {}
for set_result in set_result_list:
#.........這裏部分代碼省略.........
示例14: setup_env
def setup_env(admin_node_ip, env_name):
client = NailgunClient(admin_node_ip)
cluster_id = client.get_cluster_id(env_name)
release_id = client.get_release_id()
# delete previous cluster with the same name
if cluster_id:
client.delete_cluster(cluster_id)
for i in range(6):
cluster_id = client.get_cluster_id(env_name)
if cluster_id:
time.sleep(5)
if cluster_id:
return "Can't delete cluster"
# old cluster is gone so we're ok to create a new cluster
env = load_env(env_name)
data = env.data
if "net_provider" in env.settings:
data.update(
{
'net_provider': env.settings["net_provider"],
'net_segment_type': env.settings["net_segment_type"]
}
)
client.create_cluster(data=data)
time.sleep(5)
cluster_id = client.get_cluster_id(env_name)
# configure networks
network_conf = client.get_networks(cluster_id)
network_list = network_conf['networks']
for network in network_list:
# set vlan tags
if network["name"] in env.net_tag:
network['vlan_start'] = env.net_tag[network["name"]]
# set CIDR and related net stuff
if network["name"] in env.net_cidr:
network['cidr'] = env.net_cidr[network["name"]]
if network["name"] == "public":
if env.gateway:
network["gateway"] = env.gateway
else:
network["gateway"] = str(list(IPNetwork(network['cidr']))[1])
if network["name"] in env.net_ip_ranges:
network['ip_ranges'] = env.net_ip_ranges[network["name"]]
else:
if network["name"] == "public":
network['ip_ranges'] = get_range(network['cidr'], -1)
elif network["name"] == "floating":
network['ip_ranges'] = get_range(network['cidr'], 1)
else:
network['ip_ranges'] = get_range(network['cidr'], 0)
network['netmask'] = str(IPNetwork(network['cidr']).netmask)
network['network_size'] = len(list(IPNetwork((network['cidr']))))
network_conf['networks'] = network_list
# update neutron settings
if "net_provider" in env.settings:
if env.settings["net_provider"] == 'neutron':
# check if we need to set vlan tags
if env.settings["net_segment_type"] == 'vlan' and 'neutron_vlan_range' in env.settings:
network_conf['neutron_parameters']['L2']['phys_nets']['physnet2']['vlan_range'] = env.settings['neutron_vlan_range']
# check and update networks CIDR/netmask/size/etc
if 'net04' in env.net_cidr:
network_conf['neutron_parameters']['predefined_networks']['net04']['L3']['cidr'] = env.net_cidr['net04']
network_conf['neutron_parameters']['predefined_networks']['net04']['L3']['gateway'] = str(list(IPNetwork(env.net_cidr['net04']))[1])
if 'public' in env.net_cidr:
network_conf['neutron_parameters']['predefined_networks']['net04_ext']['L3']['cidr'] = env.net_cidr['public']
if env.gateway:
network_conf['neutron_parameters']['predefined_networks']['net04_ext']['L3']['gateway'] = env.gateway
else:
network_conf['neutron_parameters']['predefined_networks']['net04_ext']['L3']['gateway'] = str(list(IPNetwork(env.net_cidr['public']))[1])
if 'net04_ext' in env.net_ip_ranges:
network_conf['neutron_parameters']['predefined_networks']['net04_ext']['L3']['floating'] = env.net_ip_ranges["net04_ext"]
else:
network_conf['neutron_parameters']['predefined_networks']['net04_ext']['L3']['floating'] = get_range(env.net_cidr['public'], 2)
# push updated network to Fuel API
client.update_network(cluster_id, networks=network_conf, all_set=True)
# configure cluster attributes
attributes = client.get_cluster_attributes(cluster_id)
for option in env.settings:
section = False
if option in ('savanna', 'murano', 'ceilometer'):
section = 'additional_components'
if option in ('volumes_ceph', 'images_ceph', 'volumes_lvm'):
section = 'storage'
if option in ('libvirt_type', 'vlan_splinters'):
section = 'common'
if section:
#.........這裏部分代碼省略.........
示例15: FuelWebClient
class FuelWebClient(object):
def __init__(self, admin_node_ip, environment):
self.admin_node_ip = admin_node_ip
self.client = NailgunClient(admin_node_ip)
self._environment = environment
super(FuelWebClient, self).__init__()
@property
def environment(self):
"""Environment Model
:rtype: EnvironmentModel
"""
return self._environment
@staticmethod
@logwrap
def get_cluster_status(ssh_remote, smiles_count, networks_count=1):
checkers.verify_service_list(ssh_remote, smiles_count)
checkers.verify_glance_index(ssh_remote)
checkers.verify_network_list(networks_count, ssh_remote)
@logwrap
def _ostf_test_wait(self, cluster_id, timeout):
logger.info('Wait OSTF tests at cluster #%s for %s seconds',
cluster_id, timeout)
wait(
lambda: all([run['status'] == 'finished'
for run in
self.client.get_ostf_test_run(cluster_id)]),
timeout=timeout)
return self.client.get_ostf_test_run(cluster_id)
@logwrap
def _tasks_wait(self, tasks, timeout):
return [self.task_wait(task, timeout) for task in tasks]
@logwrap
def add_syslog_server(self, cluster_id, host, port):
logger.info('Add syslog server %s:%s to cluster #%s',
host, port, cluster_id)
self.client.add_syslog_server(cluster_id, host, port)
@logwrap
def assert_cluster_floating_list(self, node_name, expected_ips):
logger.info('Assert floating IPs at node %s. Expected %s',
node_name, expected_ips)
current_ips = self.get_cluster_floating_list(node_name)
assert_equal(set(expected_ips), set(current_ips),
'Current floating IPs {0}'.format(current_ips))
@logwrap
def assert_cluster_ready(self, node_name, smiles_count,
networks_count=1, timeout=300):
logger.info('Assert cluster services are UP')
remote = self.environment.get_ssh_to_remote_by_name(node_name)
_wait(
lambda: self.get_cluster_status(
remote,
smiles_count=smiles_count,
networks_count=networks_count),
timeout=timeout)
@logwrap
def assert_ostf_run_certain(self, cluster_id, tests_must_be_passed,
timeout=10 * 60):
logger.info('Assert OSTF tests are passed at cluster #%s: %s',
cluster_id, tests_must_be_passed)
set_result_list = self._ostf_test_wait(cluster_id, timeout)
tests_pass_count = 0
tests_count = len(tests_must_be_passed)
result = False
for set_result in set_result_list:
success = [test for test in set_result['tests']
if test['status'] == 'success']
for test_id in success:
for test_class in tests_must_be_passed:
if test_id['id'].find(test_class) > -1:
tests_pass_count += 1
logger.info('Passed OSTF tests %s found', test_class)
if tests_pass_count == tests_count:
result = True
assert_true(result)
@logwrap
def assert_ostf_run(self, cluster_id, should_fail=0,
failed_test_name=None, timeout=15 * 60):
logger.info('Assert OSTF run at cluster #%s. '
'Should fail %s tests named %s',
cluster_id, should_fail, failed_test_name)
set_result_list = self._ostf_test_wait(cluster_id, timeout)
failed_tests_res = []
failed = 0
actual_failed_names = []
test_result = {}
for set_result in set_result_list:
failed += len(
filter(
lambda test: test['status'] == 'failure' or
#.........這裏部分代碼省略.........