summaryrefslogtreecommitdiffstats
path: root/tests/performance.py
blob: 15b9bad82932b78498fd2268bac53040b06ad28a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# test script to evaluate Cobbler API performance
#
# Michael DeHaan <mdehaan@redhat.com>

import os
import cobbler.api as capi
import time
import sys
import random

N = 200
print "sample size is %s" % N

api = capi.BootAPI()

# part one ... create our test systems for benchmarking purposes if
# they do not seem to exist.

if not api.profiles().find("foo"):
    print "CREATE A PROFILE NAMED 'foo' to be able to run this test"
    sys.exit(0)

def random_mac():
    mac = [ 0x00, 0x16, 0x3e,
      random.randint(0x00, 0x7f),
      random.randint(0x00, 0xff),
      random.randint(0x00, 0xff) ]
    return ':'.join(map(lambda x: "%02x" % x, mac))

print "Deleting autotest entries from a previous run"
time1 = time.time()
for x in xrange(0,N):
   try:
       sys = api.systems().remove("autotest-%s" % x,with_delete=True)
   except:
       pass
time2 = time.time()
print "ELAPSED: %s seconds" % (time2 - time1)

print "Creating test systems from scratch"
time1 = time.time()
for x in xrange(0,N):
   sys = api.new_system()
   sys.set_name("autotest-%s" % x)
   sys.set_mac_address(random_mac())
   sys.set_profile("foo") # assumes there is already a foo
   # print "... adding: %s" % sys.name
   api.systems().add(sys,save=True,with_sync=False,with_triggers=False)
time2 = time.time()
print "ELAPSED %s seconds" % (time2 - time1)

for mode2 in [ "fast", "normal", "full" ]:
   for mode in [ "on", "off" ]:

       print "Running netboot edit benchmarks (turn %s, %s)" % (mode, mode2)
       time1 = time.time()
       for x in xrange(0,N):
           sys = api.systems().find("autotest-%s" % x)
           if mode == "off":
               sys.set_netboot_enabled(0)
           else:
               sys.set_netboot_enabled(1)
           # print "... editing: %s" % sys.name
           if mode2 == "fast":
               api.systems().add(sys, save=True, with_sync=False, with_triggers=False, quick_pxe_update=True)
           if mode2 == "normal":
               api.systems().add(sys, save=True, with_sync=False, with_triggers=False)
           if mode2 == "full":
               api.systems().add(sys, save=True, with_sync=True, with_triggers=True)

       time2 = time.time()
       print "ELAPSED: %s seconds" % (time2 - time1)