Skip to content

Commit

Permalink
Add docker to demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Hamilton committed Aug 11, 2018
1 parent ae362cb commit a2ce64d
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 24 deletions.
4 changes: 1 addition & 3 deletions TODO
@@ -1,6 +1,6 @@
-Generate a release on all tools.
-Profile add docker if missing template then fail.
-Jenkins support
-Setup CI build
-Look at tox
-Figure out best way to connect to KVM, ssh password is cumbersome.
-Catch exception in setup to mark profile as bad
Expand All @@ -10,9 +10,7 @@
-Handle when a profile maps to the same template.
-Check to see what happens when tpl-daemon starts but profile bogus
-Show actions in web pages and CLI
-Create a style for the web pages
-Look at Graphana
-add requirements to setup.py
-tpl-db figure out auto setup
-DEBUG=False when testpool is installed
-Change JSON output to named tuple
Expand Down
53 changes: 39 additions & 14 deletions examples/tpldemo.py
Expand Up @@ -3,8 +3,10 @@
A demo exercising testpool behavior. Read the quick start guide in
order to configure Testpool server and then come back to this script.
As this demo is running, use virt-manager and browse to testpool server
to see changes. Check the dashboard to see the status of the various
This demo supports both the fake and docker products. Fake is a good
tool for seeing behavior and development without having to setup additional
tools. The docker product requires install docker locally in order to
see the demo in action. Check the dashboard to see the status of the various
pool of resources at:
http://127.0.0.1:8000/testpool/view/dashboard
Expand All @@ -20,17 +22,23 @@
class Rest(object):
""" Example calling REST interface. """

# pylint: disable=too-many-arguments

def __init__(self, hostname):
fmt = "http://%s:8000/testpool/api/v1/"
self.url = fmt % hostname

def profile_add(self, product, name, template_name, resource_max):
def profile_add(self, name, connection, product, template_name,
resource_max):
""" Add a profile. """

params = {
"connection": connection,
"product": product,
"resource_max": resource_max,
"template_name": template_name
}
url = self.url + "profile/add/%s/%s" % (product, name)
url = self.url + "profile/add/%s" % name
rtc = requests.post(url, params=params)
rtc.raise_for_status()
return rtc
Expand All @@ -54,24 +62,37 @@ def release(self, rsrc):
return requests.get(url)


PROFILE_NAMES = ["ubuntu16.04", "centos7.0", "vmware", "ESX6.5"]
FAKE_PROFILE_NAMES = ["ubuntu16.04", "centos7.0", "vmware", "ESX6.5"]
DOCKER_PROFILE_NAMES = ["nginx"]


def add_profiles(rest, args):
""" Create all of the profiles. """

resource_maxes = [10, 40, 100, 50]

for (name, resource_max) in zip(PROFILE_NAMES, resource_maxes):
template_name = "template_name.%s" % name
logging.info("adding profile %s", name)
rest.profile_add(args.product, name, template_name, resource_max)
if args.product == "fake":
resource_maxes = [10, 40, 100, 50]
for (name, resource_max) in zip(FAKE_PROFILE_NAMES, resource_maxes):
template_name = "template_name.%s" % name
logging.info("adding profile %s", name)
rest.profile_add(name, "localhost", args.product, template_name,
resource_max)
return FAKE_PROFILE_NAMES
elif args.product == "docker":
resource_maxes = [10]
template_name = "nginx:latest"
for (name, resource_max) in zip(DOCKER_PROFILE_NAMES, resource_maxes):
logging.info("adding profile %s", name)
rest.profile_add(name, "localhost", args.product, template_name,
resource_max)
return DOCKER_PROFILE_NAMES
else:
raise ValueError("unsupported product %s" % args.product)


def remove_profiles(rest):
""" Create all of the profiles. """

for name in PROFILE_NAMES:
for name in FAKE_PROFILE_NAMES + DOCKER_PROFILE_NAMES:
try:
logging.info("remove profile %s", name)
rest.profile_remove(name, immediate=True)
Expand Down Expand Up @@ -119,7 +140,9 @@ def do_start(args):
acquired_resources = []

remove_profiles(rest)
add_profiles(rest, args)
if args.cleanup:
return 0
profile_names = add_profiles(rest, args)
count = 0

state = State()
Expand All @@ -129,7 +152,7 @@ def do_start(args):
if value == State.ACTIVE:
logging.info("acquire and releasing resources")
action = random.choice(actions)
profile = random.choice(PROFILE_NAMES)
profile = random.choice(profile_names)
if action == "acquire":
logging.info("acquire %s", profile)
resp = rest.acquire(profile)
Expand Down Expand Up @@ -180,6 +203,8 @@ def argparser(progname):
help="Location of the testpool daemon")
arg_parser.add_argument('--product', default="fake",
help="Product used for the demo")
arg_parser.add_argument('--cleanup', default=False, action="store_true",
help="Remove all demo profiles")
return arg_parser


Expand Down
1 change: 1 addition & 0 deletions testpool/core/server.py
Expand Up @@ -417,6 +417,7 @@ def main(args):
# Retrieve resources. For action items that are ready run the
# required action.
current = datetime.datetime.now()
LOGGER.info("checking actions %s", current)
rsrcs = models.Resource.objects.exclude(status=models.Resource.READY)
rsrcs = rsrcs.order_by("action_time")

Expand Down
File renamed without changes.
Expand Up @@ -42,7 +42,7 @@
def profile_add(request, name):
""" Create a profile . """

LOGGER.info("testpool_fake.api.profile_add %s", name)
LOGGER.info("testpool_docker.api.profile_add %s", name)

if request.method != 'POST':
msg = "profile_add method %s unsupported" % request.method
Expand All @@ -62,7 +62,7 @@ def profile_add(request, name):

try:
resource_max = int(resource_max)
profile1 = testpool.core.algo.profile_add("localhost", "fake", name,
profile1 = testpool.core.algo.profile_add("localhost", "docker", name,
resource_max, template_name)
serializer = ProfileSerializer(profile1)

Expand Down
Expand Up @@ -21,5 +21,5 @@

# pylint: disable=C0103
urlpatterns = [
url(r'api/v1/profile/add/fake/(?P<name>.+)', api.profile_add),
url(r'api/v1/profile/add/docker/(?P<name>.+)', api.profile_add),
]
56 changes: 56 additions & 0 deletions testpool/db/testpool_profile/api.py
Expand Up @@ -192,3 +192,59 @@ def profile_remove(request, profile_name):
msg = "profile_release method %s unsupported" % request.method
logging.error(msg)
return JsonResponse({"msg": msg}, status=405)


@csrf_exempt
def profile_add(request, profile_name):
""" Add a profile . """

print "MARK: 1"

LOGGER.info("testpool_profile.api.profile_add %s", profile_name)

if request.method != 'POST':
msg = "profile_add method %s unsupported" % request.method
logging.error(msg)
return JsonResponse({"msg": msg}, status=405)

if "resource_max" not in request.GET:
msg = "profile_add requires resource_max"
return JsonResponse({"msg": msg}, status=404)

if "template_name" not in request.GET:
msg = "profile_add requires template_name"
return JsonResponse({"msg": msg}, status=404)

print "MARK: 2"

if "connection" not in request.GET:
msg = "profile_add requires connection"
return JsonResponse({"msg": msg}, status=404)
print "MARK: 3"

if "product" not in request.GET:
msg = "profile_add requires product"
return JsonResponse({"msg": msg}, status=404)

print "MARK: 4"

resource_max = request.GET["resource_max"]
template_name = request.GET["template_name"]
connection = request.GET["connection"]
product = request.GET["product"]

try:
resource_max = int(resource_max)
profile1 = testpool.core.algo.profile_add(connection, product,
profile_name, resource_max,
template_name)
serializer = ProfileSerializer(profile1)

return JSONResponse(serializer.data)
except Profile.DoesNotExist, arg:
msg = "profile %s not found" % profile_name
logging.error(msg)
return JsonResponse({"msg": msg}, status=403)
except Exception, arg:
logging.error(arg)
return JsonResponse({"msg": arg}, status=500)
2 changes: 2 additions & 0 deletions testpool/db/testpool_profile/urls.py
Expand Up @@ -30,6 +30,8 @@
url(r'api/v1/profile/list', api.profile_list),
url(r'api/v1/profile/remove/(?P<profile_name>[\.\w]+$)',
api.profile_remove),
url(r'api/v1/profile/add/(?P<profile_name>[\.\w]+$)',
api.profile_add),
url(r"view/profile/detail/(?P<profile>.+)", views.detail),
url(r"view/profiles", views.profile_list),
url(r"view/dashboard", views.dashboard),
Expand Down
8 changes: 4 additions & 4 deletions testpool/libexec/docker/api.py
Expand Up @@ -58,13 +58,13 @@ def timing_get(self, request):
""" Return algorithm timing based on the request. """

if request == testpool.core.api.Pool.TIMING_REQUEST_DESTROY:
return 60
return 10
elif request == testpool.core.api.Pool.TIMING_REQUEST_ATTR:
return 1
return 5
elif request == testpool.core.api.Pool.TIMING_REQUEST_CLONE:
return 30
return 20
elif request == testpool.core.api.Pool.TIMING_REQUEST_NONE:
return 1
return 30
else:
raise ValueError("unknown timing request %s" % request)

Expand Down

0 comments on commit a2ce64d

Please sign in to comment.