Refactored the compute model and its elements

In this changeset, I refactored the whole Watcher codebase to
adopt a naming convention about the various elements of the
Compute model so that it reflects the same naming convention
adopted by Nova.

Change-Id: I28adba5e1f27175f025330417b072686134d5f51
Partially-Implements: blueprint cluster-model-objects-wrapper
This commit is contained in:
Vincent Françoise
2016-07-06 17:44:29 +02:00
parent dbde1afea0
commit 31c37342cd
53 changed files with 1865 additions and 1803 deletions

View File

@@ -40,7 +40,7 @@ class NovaHelper(object):
self.nova = self.osc.nova()
self.glance = self.osc.glance()
def get_hypervisors_list(self):
def get_compute_node_list(self):
return self.nova.hypervisors.list()
def find_instance(self, instance_id):
@@ -54,7 +54,26 @@ class NovaHelper(object):
break
return instance
def watcher_non_live_migrate_instance(self, instance_id, hypervisor_id,
def wait_for_volume_status(self, volume, status, timeout=60,
poll_interval=1):
"""Wait until volume reaches given status.
:param volume: volume resource
:param status: expected status of volume
:param timeout: timeout in seconds
:param poll_interval: poll interval in seconds
"""
start_time = time.time()
while time.time() - start_time < timeout:
volume = self.cinder.volumes.get(volume.id)
if volume.status == status:
break
time.sleep(poll_interval)
else:
raise Exception("Volume %s did not reach status %s after %d s"
% (volume.id, status, timeout))
def watcher_non_live_migrate_instance(self, instance_id, node_id,
keep_original_image_name=True):
"""This method migrates a given instance
@@ -218,7 +237,7 @@ class NovaHelper(object):
# We create the new instance from
# the intermediate image of the original instance
new_instance = self. \
create_instance(hypervisor_id,
create_instance(node_id,
instance_name,
image_uuid,
flavor_name,
@@ -358,7 +377,7 @@ class NovaHelper(object):
# Sets the compute host's ability to accept new instances.
# host_maintenance_mode(self, host, mode):
# Start/Stop host maintenance window.
# On start, it triggers guest VMs evacuation.
# On start, it triggers guest instances evacuation.
host = self.nova.hosts.get(hostname)
if not host:
@@ -463,20 +482,20 @@ class NovaHelper(object):
else:
self.nova.servers.stop(instance_id)
if self.wait_for_vm_state(instance, "stopped", 8, 10):
if self.wait_for_instance_state(instance, "stopped", 8, 10):
LOG.debug("Instance %s stopped." % instance_id)
return True
else:
return False
def wait_for_vm_state(self, server, vm_state, retry, sleep):
"""Waits for server to be in a specific vm_state
def wait_for_instance_state(self, server, state, retry, sleep):
"""Waits for server to be in a specific state
The vm_state can be one of the following :
The state can be one of the following :
active, stopped
:param server: server object.
:param vm_state: for which state we are waiting for
:param state: for which state we are waiting for
:param retry: how many times to retry
:param sleep: seconds to sleep between the retries
"""
@@ -484,11 +503,11 @@ class NovaHelper(object):
if not server:
return False
while getattr(server, 'OS-EXT-STS:vm_state') != vm_state and retry:
while getattr(server, 'OS-EXT-STS:vm_state') != state and retry:
time.sleep(sleep)
server = self.nova.servers.get(server)
retry -= 1
return getattr(server, 'OS-EXT-STS:vm_state') == vm_state
return getattr(server, 'OS-EXT-STS:vm_state') == state
def wait_for_instance_status(self, instance, status_list, retry, sleep):
"""Waits for instance to be in a specific status
@@ -514,7 +533,7 @@ class NovaHelper(object):
LOG.debug("Current instance status: %s" % instance.status)
return instance.status in status_list
def create_instance(self, hypervisor_id, inst_name="test", image_id=None,
def create_instance(self, node_id, inst_name="test", image_id=None,
flavor_name="m1.tiny",
sec_group_list=["default"],
network_names_list=["demo-net"], keypair_name="mykeys",
@@ -570,15 +589,14 @@ class NovaHelper(object):
net_obj = {"net-id": nic_id}
net_list.append(net_obj)
instance = self.nova.servers. \
create(inst_name,
image, flavor=flavor,
key_name=keypair_name,
security_groups=sec_group_list,
nics=net_list,
block_device_mapping_v2=block_device_mapping_v2,
availability_zone="nova:" +
hypervisor_id)
instance = self.nova.servers.create(
inst_name, image,
flavor=flavor,
key_name=keypair_name,
security_groups=sec_group_list,
nics=net_list,
block_device_mapping_v2=block_device_mapping_v2,
availability_zone="nova:%s" % node_id)
# Poll at 5 second intervals, until the status is no longer 'BUILD'
if instance:
@@ -609,13 +627,13 @@ class NovaHelper(object):
return network_id
def get_vms_by_hypervisor(self, host):
return [vm for vm in
def get_instances_by_node(self, host):
return [instance for instance in
self.nova.servers.list(search_opts={"all_tenants": True})
if self.get_hostname(vm) == host]
if self.get_hostname(instance) == host]
def get_hostname(self, vm):
return str(getattr(vm, 'OS-EXT-SRV-ATTR:host'))
def get_hostname(self, instance):
return str(getattr(instance, 'OS-EXT-SRV-ATTR:host'))
def get_flavor_instance(self, instance, cache):
fid = instance.flavor['id']