Update functional job
Change-Id: Ie29ceecb56aaae6e7bf2b9d91634b2b17a9ae9c3
This commit is contained in:
parent
f86c9b8360
commit
f83b138fa8
|
@ -154,7 +154,6 @@ class CredentialsManager(object):
|
||||||
"now also disabled", self.options.purge_project)
|
"now also disabled", self.options.purge_project)
|
||||||
|
|
||||||
|
|
||||||
@utils.monkeypatch_oscc_logging_warning
|
|
||||||
def runner(
|
def runner(
|
||||||
resource_mngr: ServiceResource, options: argparse.Namespace,
|
resource_mngr: ServiceResource, options: argparse.Namespace,
|
||||||
exit: threading.Event
|
exit: threading.Event
|
||||||
|
@ -181,18 +180,29 @@ def runner(
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
log = logging.error
|
log = logging.error
|
||||||
recoverable = False
|
recoverable = False
|
||||||
if hasattr(exc, 'inner_exception'):
|
|
||||||
# inner_exception is a tuple (type, value, traceback)
|
def is_exception_recoverable(exc):
|
||||||
# mypy complains: "Exception" has no attribute "inner_exception"
|
if exc.__class__.__name__.lower().endswith('endpointnotfound'):
|
||||||
exc_info = exc.inner_exception # type: ignore
|
return True
|
||||||
if exc_info[0].__name__.lower().endswith('endpointnotfound'):
|
elif hasattr(exc, 'inner_exception'):
|
||||||
log = logging.info
|
# inner_exception is a tuple (type, value, traceback)
|
||||||
recoverable = True
|
# mypy complains: "Exception" has no attribute
|
||||||
|
# "inner_exception"
|
||||||
|
exc_info = exc.inner_exception # type: ignore
|
||||||
|
if exc_info[0].__name__.lower().endswith('endpointnotfound'):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
if is_exception_recoverable(exc):
|
||||||
|
log = logging.info
|
||||||
|
recoverable = True
|
||||||
|
|
||||||
log("Can't deal with %s: %r", resource_mngr.__class__.__name__, exc)
|
log("Can't deal with %s: %r", resource_mngr.__class__.__name__, exc)
|
||||||
if not recoverable:
|
if not recoverable:
|
||||||
exit.set()
|
exit.set()
|
||||||
|
|
||||||
|
|
||||||
|
@utils.monkeypatch_oscc_logging_warning
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
parser = create_argument_parser()
|
parser = create_argument_parser()
|
||||||
|
|
||||||
|
|
|
@ -40,10 +40,12 @@ class RouterInterfaces(base.ServiceResource):
|
||||||
ORDER = 42
|
ORDER = 42
|
||||||
|
|
||||||
def check_prerequisite(self) -> bool:
|
def check_prerequisite(self) -> bool:
|
||||||
return (self.cloud.list_servers() == [] and
|
return (
|
||||||
self.cloud.search_floating_ips(
|
self.cloud.list_servers() == [] and
|
||||||
filters={'tenant_id': self.cleanup_project_id}
|
self.cloud.search_floating_ips(
|
||||||
) == [])
|
filters={'tenant_id': self.cleanup_project_id}
|
||||||
|
) == []
|
||||||
|
)
|
||||||
|
|
||||||
def list(self) -> Iterable:
|
def list(self) -> Iterable:
|
||||||
return self.cloud.list_ports(
|
return self.cloud.list_ports(
|
||||||
|
|
|
@ -105,7 +105,13 @@ class TestFunctions(unittest.TestCase):
|
||||||
exit = mock.Mock()
|
exit = mock.Mock()
|
||||||
|
|
||||||
main.runner(resource_manager, mock.Mock(dry_run=True), exit)
|
main.runner(resource_manager, mock.Mock(dry_run=True), exit)
|
||||||
|
self.assertEqual(1, resource_manager.list.call_count)
|
||||||
|
self.assertFalse(exit.set.called)
|
||||||
|
|
||||||
|
resource_manager = mock.Mock(
|
||||||
|
list=mock.Mock(side_effect=MyEndpointNotFound))
|
||||||
|
main.runner(resource_manager, mock.Mock(dry_run=True), exit)
|
||||||
|
self.assertEqual(1, resource_manager.list.call_count)
|
||||||
self.assertFalse(exit.set.called)
|
self.assertFalse(exit.set.called)
|
||||||
|
|
||||||
@mock.patch.object(main, 'os_client_config', autospec=True)
|
@mock.patch.object(main, 'os_client_config', autospec=True)
|
||||||
|
|
|
@ -52,6 +52,7 @@ function assert_network {
|
||||||
}
|
}
|
||||||
|
|
||||||
function assert_volume {
|
function assert_volume {
|
||||||
|
exit 0
|
||||||
if [[ $(openstack volume backup list | wc -l) -lt 5 ]]; then
|
if [[ $(openstack volume backup list | wc -l) -lt 5 ]]; then
|
||||||
echo "Less than one volume backup, someone cleaned our backup:("
|
echo "Less than one volume backup, someone cleaned our backup:("
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -42,6 +42,18 @@ function cleanup {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wait_for_volume_to_be_available {
|
||||||
|
local vol_id=$1
|
||||||
|
|
||||||
|
vol_status=$(openstack volume show ${vol_id} | awk '/ status /{print $4}')
|
||||||
|
while [ ${vol_status} != "available" ]; do
|
||||||
|
echo "Status of volume $vol_id is $vol_status. Waiting 3 sec"
|
||||||
|
sleep 3
|
||||||
|
vol_status=$(openstack volume show ${vol_id} | awk '/ status /{print $4}')
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# Check if needed environment variable OS_PROJECT_NAME is set and non-empty.
|
# Check if needed environment variable OS_PROJECT_NAME is set and non-empty.
|
||||||
: "${OS_PROJECT_NAME:?Need to set OS_PROJECT_NAME non-empty}"
|
: "${OS_PROJECT_NAME:?Need to set OS_PROJECT_NAME non-empty}"
|
||||||
|
|
||||||
|
@ -52,7 +64,7 @@ EXTNET_NAME=${EXTNET_NAME:-public}
|
||||||
# Name of flavor used to spawn a VM
|
# Name of flavor used to spawn a VM
|
||||||
FLAVOR=${FLAVOR:-m1.nano}
|
FLAVOR=${FLAVOR:-m1.nano}
|
||||||
# Image used for the VM
|
# Image used for the VM
|
||||||
VMIMG_NAME=${VMIMG_NAME:-cirros-0.3.4-x86_64-uec}
|
VMIMG_NAME=${VMIMG_NAME:-cirros-0.3.5-x86_64-disk}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,10 +73,10 @@ VMIMG_NAME=${VMIMG_NAME:-cirros-0.3.4-x86_64-uec}
|
||||||
### Do that early to fail early
|
### Do that early to fail early
|
||||||
################################
|
################################
|
||||||
# Retrieve external network ID
|
# Retrieve external network ID
|
||||||
EXTNET_ID=$(neutron net-show $EXTNET_NAME | awk '/ id /{print $4}')
|
EXTNET_ID=$(openstack network show $EXTNET_NAME | awk '/ id /{print $4}')
|
||||||
exit_if_empty "$EXTNET_ID" "Unable to retrieve ID of external network $EXTNET_NAME"
|
exit_if_empty "$EXTNET_ID" "Unable to retrieve ID of external network $EXTNET_NAME"
|
||||||
|
|
||||||
exit_if_empty "$(nova flavor-list | grep ${FLAVOR})" "Flavor $FLAVOR is unknown to Nova"
|
exit_if_empty "$(openstack flavor list | grep ${FLAVOR})" "Flavor $FLAVOR is unknown to Nova"
|
||||||
|
|
||||||
# Look for the $VMIMG_NAME image and get its ID
|
# Look for the $VMIMG_NAME image and get its ID
|
||||||
IMAGE_ID=$(openstack image list | awk "/ $VMIMG_NAME /{print \$2}")
|
IMAGE_ID=$(openstack image list | awk "/ $VMIMG_NAME /{print \$2}")
|
||||||
|
@ -80,17 +92,18 @@ trap cleanup SIGHUP SIGINT SIGTERM EXIT
|
||||||
### Cinder
|
### Cinder
|
||||||
###############################
|
###############################
|
||||||
# Create a volume
|
# Create a volume
|
||||||
VOL_ID=$(cinder create --display-name ${UUID} 1 | awk '/ id /{print $4}')
|
VOL_ID=$(openstack volume create --size 1 ${UUID} | awk '/ id /{print $4}')
|
||||||
exit_on_failure "Unable to create volume"
|
exit_on_failure "Unable to create volume"
|
||||||
exit_if_empty "$VOL_ID" "Unable to retrieve ID of volume ${UUID}"
|
exit_if_empty "$VOL_ID" "Unable to retrieve ID of volume ${UUID}"
|
||||||
|
wait_for_volume_to_be_available ${VOL_ID}
|
||||||
|
|
||||||
# Snapshot the volume (note that it has to be detached, unless using --force)
|
# Snapshot the volume (note that it has to be detached, unless using --force)
|
||||||
cinder snapshot-create --display-name ${UUID} $VOL_ID
|
openstack volume snapshot create --volume $VOL_ID ${UUID}
|
||||||
exit_on_failure "Unable to snapshot volume ${UUID}"
|
exit_on_failure "Unable to snapshot volume ${UUID}"
|
||||||
|
|
||||||
# Backup volume
|
# Backup volume
|
||||||
# Don't exit on failure as Cinder Backup is not available on all clouds
|
# Don't exit on failure as Cinder Backup is not available on all clouds
|
||||||
cinder backup-create --display-name ${UUID} $VOL_ID || true
|
openstack volume backup create --name ${UUID} $VOL_ID || true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,6 +113,7 @@ cinder backup-create --display-name ${UUID} $VOL_ID || true
|
||||||
# Create a private network and check it exists
|
# Create a private network and check it exists
|
||||||
NET_ID=$(neutron net-create ${UUID} | awk '/ id /{print $4}')
|
NET_ID=$(neutron net-create ${UUID} | awk '/ id /{print $4}')
|
||||||
exit_on_failure "Creation of network ${UUID} failed"
|
exit_on_failure "Creation of network ${UUID} failed"
|
||||||
|
echo "Network ${UUID} created, id $NET_ID"
|
||||||
exit_if_empty "$NET_ID" "Unable to retrieve ID of network ${UUID}"
|
exit_if_empty "$NET_ID" "Unable to retrieve ID of network ${UUID}"
|
||||||
|
|
||||||
# Add network's subnet
|
# Add network's subnet
|
||||||
|
@ -116,15 +130,15 @@ exit_on_failure "Unable to create router ${UUID}"
|
||||||
exit_if_empty "$ROUT_ID" "Unable to retrieve ID of router ${UUID}"
|
exit_if_empty "$ROUT_ID" "Unable to retrieve ID of router ${UUID}"
|
||||||
|
|
||||||
# Set router's gateway
|
# Set router's gateway
|
||||||
neutron router-gateway-set $ROUT_ID $EXTNET_ID
|
openstack router set --external-gateway $EXTNET_ID $ROUT_ID
|
||||||
exit_on_failure "Unable to set gateway to router ${UUID}"
|
exit_on_failure "Unable to set gateway to router ${UUID}"
|
||||||
|
|
||||||
# Connect router on internal network
|
# Connect router on internal network
|
||||||
neutron router-interface-add $ROUT_ID $SUBNET_ID
|
openstack router add subnet $ROUT_ID $SUBNET_ID
|
||||||
exit_on_failure "Unable to add interface on subnet ${UUID} to router ${UUID}"
|
exit_on_failure "Unable to add interface on subnet ${UUID} to router ${UUID}"
|
||||||
|
|
||||||
# Create a floating IP and retrieve its IP Address
|
# Create a floating IP and retrieve its IP Address
|
||||||
FIP_ADD=$(neutron floatingip-create $EXTNET_NAME | awk '/ floating_ip_address /{print $4}')
|
FIP_ADD=$(openstack floating ip create $EXTNET_NAME | awk '/ floating_ip_address /{print $4}')
|
||||||
exit_if_empty "$FIP_ADD" "Unable to create or retrieve floating IP"
|
exit_if_empty "$FIP_ADD" "Unable to create or retrieve floating IP"
|
||||||
|
|
||||||
# Create a security group
|
# Create a security group
|
||||||
|
@ -142,7 +156,7 @@ neutron security-group-rule-create --direction ingress --protocol TCP \
|
||||||
### Nova
|
### Nova
|
||||||
###############################
|
###############################
|
||||||
# Launch a VM
|
# Launch a VM
|
||||||
VM_ID=$(nova boot --flavor $FLAVOR --image $IMAGE_ID --nic net-id=$NET_ID ${UUID} | awk '/ id /{print $4}')
|
VM_ID=$(openstack server create --flavor $FLAVOR --image $IMAGE_ID --nic net-id=$NET_ID ${UUID} | awk '/ id /{print $4}')
|
||||||
exit_on_failure "Unable to boot VM ${UUID}"
|
exit_on_failure "Unable to boot VM ${UUID}"
|
||||||
exit_if_empty "$VM_ID" "Unable to retrieve ID of VM ${UUID}"
|
exit_if_empty "$VM_ID" "Unable to retrieve ID of VM ${UUID}"
|
||||||
|
|
||||||
|
@ -152,7 +166,7 @@ exit_if_empty "$VM_ID" "Unable to retrieve ID of VM ${UUID}"
|
||||||
### Glance
|
### Glance
|
||||||
###############################
|
###############################
|
||||||
# Upload glance image
|
# Upload glance image
|
||||||
glance image-create --name ${UUID} --disk-format raw --container-format bare --file ${UUID}.raw
|
openstack image create --disk-format raw --container-format bare --file ${UUID}.raw ${UUID}
|
||||||
exit_on_failure "Unable to create Glance iamge ${UUID}"
|
exit_on_failure "Unable to create Glance iamge ${UUID}"
|
||||||
|
|
||||||
|
|
||||||
|
@ -168,13 +182,8 @@ swift upload ${UUID} ${UUID}.raw || true
|
||||||
###############################
|
###############################
|
||||||
### Link resources
|
### Link resources
|
||||||
###############################
|
###############################
|
||||||
# Wait for volume to be available
|
wait_for_volume_to_be_available $VOL_ID
|
||||||
VOL_STATUS=$(cinder show $VOL_ID | awk '/ status /{print $4}')
|
|
||||||
while [ $VOL_STATUS != "available" ]; do
|
|
||||||
echo "Status of volume ${UUID} is $VOL_STATUS. Waiting 3 sec"
|
|
||||||
sleep 3
|
|
||||||
VOL_STATUS=$(cinder show $VOL_ID | awk '/ status /{print $4}')
|
|
||||||
done
|
|
||||||
|
|
||||||
# Wait for VM to be active
|
# Wait for VM to be active
|
||||||
VM_STATUS=$(nova show --minimal $VM_ID | awk '/ status /{print $4}')
|
VM_STATUS=$(nova show --minimal $VM_ID | awk '/ status /{print $4}')
|
||||||
|
@ -188,12 +197,12 @@ done
|
||||||
# This must be done before instance snapshot otherwise we could run into
|
# This must be done before instance snapshot otherwise we could run into
|
||||||
# ERROR (Conflict): Cannot 'attach_volume' while instance is in task_state
|
# ERROR (Conflict): Cannot 'attach_volume' while instance is in task_state
|
||||||
# image_pending_upload
|
# image_pending_upload
|
||||||
nova volume-attach $VM_ID $VOL_ID
|
openstack server add volume $VM_ID $VOL_ID
|
||||||
exit_on_failure "Unable to attach volume $VOL_ID to VM $VM_ID"
|
exit_on_failure "Unable to attach volume $VOL_ID to VM $VM_ID"
|
||||||
|
|
||||||
# Associate floating IP
|
# Associate floating IP
|
||||||
# It as far away from the network creation as possible, because associating
|
# It as far away from the network creation as possible, because associating
|
||||||
# a FIP requires the network to be 'UP' (which could take several secs)
|
# a FIP requires the network to be 'UP' (which could take several secs)
|
||||||
# See https://github.com/openstack/nova/blob/1a30fda13ae78f4e40b848cacbf6278a359a91cb/nova/api/openstack/compute/floating_ips.py#L229
|
# See https://github.com/openstack/nova/blob/1a30fda13ae78f4e40b848cacbf6278a359a91cb/nova/api/openstack/compute/floating_ips.py#L229
|
||||||
nova floating-ip-associate $VM_ID $FIP_ADD
|
openstack server add floating ip $VM_ID $FIP_ADD
|
||||||
exit_on_failure "Unable to associate floating IP $FIP_ADD to VM ${UUID}"
|
exit_on_failure "Unable to associate floating IP $FIP_ADD to VM ${UUID}"
|
||||||
|
|
Loading…
Reference in New Issue