← Back to team overview

canonical-ubuntu-qa team mailing list archive

[Merge] autopkgtest-cloud:no-floating-ip into autopkgtest-cloud:master

 

Brian Murray has proposed merging autopkgtest-cloud:no-floating-ip into autopkgtest-cloud:master.

Requested reviews:
  Canonical's Ubuntu QA (canonical-ubuntu-qa)

For more details, see:
https://code.launchpad.net/~ubuntu-release/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/455266

With the move to PS5 we can no longer get a floating IP which is actually great because then the IPs won't change with a redeploy.
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of autopkgtest-cloud:no-floating-ip into autopkgtest-cloud:master.
diff --git a/mojo/add-floating-ip b/mojo/add-floating-ip
deleted file mode 100755
index a183b7d..0000000
--- a/mojo/add-floating-ip
+++ /dev/null
@@ -1,181 +0,0 @@
-#!/usr/bin/python
-#
-# Authors:      Paul Gear, Neale Pickett
-# Description:  Manage floating IP allocations in mojo local directory for a juju service or unit.
-# NOTE:         $MOJO_PROJECT and $MOJO_STAGE must be set before calling this script.
-#
-
-import json
-import os
-import subprocess
-import sys
-
-import novaclient.client
-
-SECRETS_DIR = os.path.join(
-    os.getenv("MOJO_ROOT", "/srv/mojo"),
-    "LOCAL",
-    os.environ["MOJO_PROJECT"],
-    os.environ["MOJO_STAGE"],
-)
-
-
-status = json.loads(
-    subprocess.check_output(["juju", "status", "--format=json"])
-)
-services = status.get("applications")
-if services is None:
-    services = status["services"]
-
-nova_tenant = novaclient.client.Client(
-    "1.1",
-    os.environ["OS_USERNAME"],
-    os.environ["OS_PASSWORD"],
-    os.environ["OS_TENANT_NAME"],
-    os.environ["OS_AUTH_URL"],
-)
-
-
-def get_ip_pool():
-    pool = os.environ.get("MOJO_FLOATING_IP_POOL")
-    if pool is not None:
-        return pool
-
-    if os.environ["OS_USERNAME"].startswith(
-        ("stg-", "stg_", "is-mojo-deployer")
-    ):
-        return "staging_ext_net"
-    return "ext_net"
-
-
-def units_in_service(service_name):
-    units = services[service_name]["units"]
-    return units.keys()
-
-
-def machine_of_unit(unit_name):
-    service_name, _ = unit_name.split("/", 1)
-
-    unit = services[service_name]["units"][unit_name]
-    machine_no = unit["machine"]
-    machine = status["machines"][machine_no]
-
-    return machine
-
-
-def get_unit_floating_ip(unit_name):
-    machine = machine_of_unit(unit_name)
-
-    server = nova_tenant.servers.find(id=machine["instance-id"])
-
-    # If we already have a floating IP associated, use that.
-    try:
-        fip = nova_tenant.floating_ips.find(instance_id=server.id)
-        return fip.ip
-    except Exception:
-        pass
-
-    unitfn = os.path.join(SECRETS_DIR, unit_name.replace("/", ".") + ".ip")
-
-    # Rename older standard
-    oldunitfn = os.path.join(SECRETS_DIR, unit_name.replace("/", "_"))
-    try:
-        os.rename(oldunitfn, unitfn)
-    except Exception:
-        pass
-
-    # Read IP from state file.
-    try:
-        myip = open(unitfn).read().strip()
-    except Exception:
-        myip = None
-
-    # Create a new floating IP to use
-    if not myip:
-        unitf = open(unitfn, "w")
-        fip = nova_tenant.floating_ips.create(get_ip_pool())
-        myip = fip.ip
-        unitf.write(myip)
-        unitf.close()
-    else:
-        try:
-            # Get the existing one
-            fip = nova_tenant.floating_ips.find(ip=myip)
-        except Exception:
-            # If this happens you're going to need to either get that back in the list,
-            # or blow away the state file so it gets a new IP.
-            # pylint: disable=raise-missing-from
-            raise (
-                RuntimeError(
-                    "Desired IP {} not in floating ips list!".format(myip)
-                )
-            )
-
-    if fip.instance_id:
-        # If it's already associated, ensure it's associated to us
-        machine_id = machine.get("Id")
-        if machine_id is None:
-            machine_id = machine["instance-id"]
-        if fip.instance_id != machine_id:
-            raise (
-                RuntimeError(
-                    "IP {} is associated, but not to {}!".format(
-                        myip, unit_name
-                    )
-                )
-            )
-        return myip
-
-    # Go associate it now
-    server.add_floating_ip(fip)
-
-    return myip
-
-
-def usage():
-    print(
-        """Usage: {} [SERVICE|UNIT]
-
-# Add a floating IP to the apache2/0 unit:
-add-floating-ip apache2/0
-
-# Add floating IPs to all units the jenkins-slave service:
-add-floating-ip jenkins-slave
-
-# Add floating IPs to all units in the haproxy and squid services:
-add-floating-ip haproxy squid
-
-# Add floating IPs to the apache2/0 and apache2/1 units:
-export targets="apache2/0 apache2/1"
-add-floating-ip
-""".format(
-            "add-floating-ip"
-        )
-    )
-
-
-def main():
-    if len(sys.argv) >= 2:
-        args = sys.argv[1:]
-    elif "targets" in os.environ:
-        args = os.environ["targets"].split()
-    else:
-        return usage()
-
-    for arg in args:
-        if "/" not in arg:
-            service_name = arg
-            print("{}:".format(service_name))
-            unit_names = units_in_service(service_name)
-            unit_names.sort()
-            for unit_name in unit_names:
-                ip = get_unit_floating_ip(unit_name)
-                print("- {}: {}".format(unit_name, ip))
-        else:
-            unit_name = arg
-            ip = get_unit_floating_ip(unit_name)
-            print("{}: {}".format(unit_name, ip))
-
-
-if __name__ == "__main__":
-    main()
diff --git a/mojo/postdeploy b/mojo/postdeploy
deleted file mode 100755
index 79fe50a..0000000
--- a/mojo/postdeploy
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/bash
-
-set -eu
-
-if [ "${MOJO_STAGE_NAME}" == "devel" ]; then
-    exit 0
-fi
-
-if [ "${MOJO_STAGE_NAME}" == "staging" ]; then
-    set -xv
-fi
-
-echo "Setting up the floating IP address of the front end..."
-"$(dirname "$0")/add-floating-ip" haproxy
-"$(dirname "$0")/add-floating-ip" rabbitmq-server