Alternating colors for debug. Change ntp server to

array. Remove some useless printing.
This commit is contained in:
Michael Chapman
2013-09-27 22:40:30 +10:00
parent 87a0b22271
commit cb2711a3da
4 changed files with 35 additions and 32 deletions

View File

@@ -43,7 +43,7 @@ host {
} }
class { ntp: class { ntp:
servers => 'ntp.esl.cisco.com', servers => [ 'ntp.esl.cisco.com' ],
autoupdate => true, autoupdate => true,
} }

View File

@@ -27,7 +27,7 @@ def main():
parser_make.add_argument('-p', '--data_path', default='./data', help='Path to the data directory containing yaml config') parser_make.add_argument('-p', '--data_path', default='./data', help='Path to the data directory containing yaml config')
parser_make.add_argument('-f', '--fragment_path', default='./stack-builder/fragments', help='Path to config fragments') parser_make.add_argument('-f', '--fragment_path', default='./stack-builder/fragments', help='Path to config fragments')
#parser_make.add_argument('-n', '--noop', action='store_false', help='Make no API calls, just print what would have been done') #parser_make.add_argument('-n', '--noop', action='store_false', help='Make no API calls, just print what would have been done')
parser_make.add_argument('-d', '--debug', action='store_false', help='print debug output') parser_make.add_argument('-d', '--debug', action='store_true', help='print debug output')
parser_make.set_defaults(func=make) parser_make.set_defaults(func=make)
parser_get = subparsers.add_parser('get', help='get help') parser_get = subparsers.add_parser('get', help='get help')
@@ -47,7 +47,6 @@ def main():
parser_frag.set_defaults(func=show) parser_frag.set_defaults(func=show)
args = parser.parse_args() args = parser.parse_args()
print args
args.func(n, q, args) args.func(n, q, args)

View File

@@ -7,7 +7,7 @@
and pushing the appropriate metadata and init scripts to them and pushing the appropriate metadata and init scripts to them
""" """
import debug
import subprocess import subprocess
import os import os
import uuid import uuid
@@ -17,9 +17,6 @@ import fragment
from metadata import build_metadata from metadata import build_metadata
from debug import dprint from debug import dprint
debug = False
noop = False
def build_server_deploy(): def build_server_deploy():
with open ('./stack-builder/fragments/build-config.sh', 'r') as b: with open ('./stack-builder/fragments/build-config.sh', 'r') as b:
return b.read() return b.read()
@@ -111,7 +108,6 @@ def make_subnet(q, ci_network_name, test_net, index=1, dhcp=True, gateway=False)
return test_subnet return test_subnet
def boot_puppetised_instance(n, name, image, nic_list, key='m', os_flavor=u'm1.medium',deploy="",files=None, meta={}): def boot_puppetised_instance(n, name, image, nic_list, key='m', os_flavor=u'm1.medium',deploy="",files=None, meta={}):
dprint("Booting " + name)
images = n.images.list() images = n.images.list()
for i,image in enumerate([image.name for image in images]): for i,image in enumerate([image.name for image in images]):
if image == image: if image == image:
@@ -123,13 +119,13 @@ def boot_puppetised_instance(n, name, image, nic_list, key='m', os_flavor=u'm1.m
boot_flavor = flavors[i] boot_flavor = flavors[i]
print("Booting " + name) print("Booting " + name)
dprint("Boot image:" + str(boot_image)) dprint("Boot image: " + str(boot_image))
dprint("Boot flavor:" + str(boot_flavor)) dprint("Boot flavor: " + str(boot_flavor))
dprint("Boot nics" + str(nic_list)) dprint("Boot nics: " + str(nic_list))
dprint("Boot key" + str(key)) dprint("Boot key: " + str(key))
dprint("Boot deploy" + str(deploy)) dprint("Boot deploy: " + str(deploy))
dprint("Boot files" + str(files)) dprint("Boot files: " + str(files))
dprint("Boot meta" + str(meta)) dprint("Boot meta: " + str(meta))
return n.servers.create(name, image=boot_image, flavor=boot_flavor, userdata=deploy, files=files, key_name=key, nics=nic_list, config_drive=True, meta=meta) return n.servers.create(name, image=boot_image, flavor=boot_flavor, userdata=deploy, files=files, key_name=key, nics=nic_list, config_drive=True, meta=meta)
@@ -192,12 +188,9 @@ def make(n, q, args):
data_path = args.data_path data_path = args.data_path
fragment_path = args.fragment_path fragment_path = args.fragment_path
# These are globals
if args.debug: if args.debug:
debug = True print 'Debugging is on!'
if args.noop: debug.debug = True
noop = True
test_id = uuid.uuid4().hex test_id = uuid.uuid4().hex
print "Running test: " + test_id print "Running test: " + test_id
@@ -231,7 +224,8 @@ def make(n, q, args):
# Not sure if we need this # Not sure if we need this
control_node_internal = net1_ports[0]['fixed_ips'][0]['ip_address'] control_node_internal = net1_ports[0]['fixed_ips'][0]['ip_address']
config_meta = build_metadata(data_path) config_meta = build_metadata(data_path)
dprint('Metadata Without hardcodes ' + str(config_meta))
# Put this into metadata and parse it on-node # Put this into metadata and parse it on-node
# from config drive. There are limits on the count # from config drive. There are limits on the count
# according to the doc but TODO confirm this # according to the doc but TODO confirm this
@@ -252,13 +246,16 @@ def make(n, q, args):
#'installer_repo' : 'michaeltchapman' #'installer_repo' : 'michaeltchapman'
}) })
dprint('Metadata With hardcodes ' + str(config_meta))
dprint("Metadata:\n" + str(config_meta))
build_deploy = fragment.compose('build-server', data_path, fragment_path, scenario, config_meta) build_deploy = fragment.compose('build-server', data_path, fragment_path, scenario, config_meta)
control_deploy = fragment.compose('control-server', data_path, fragment_path, scenario, config_meta) control_deploy = fragment.compose('control-server', data_path, fragment_path, scenario, config_meta)
compute_deploy = fragment.compose('compute-server02', data_path, fragment_path, scenario, config_meta) compute_deploy = fragment.compose('compute-server02', data_path, fragment_path, scenario, config_meta)
dprint('build_deploy: ' + str(build_deploy))
dprint('control_deploy: ' + str(control_deploy))
dprint('compute_deploy: ' + str(compute_deploy))
build_node = boot_puppetised_instance(n, build_node = boot_puppetised_instance(n,
'build-server', 'build-server',
image, image,
@@ -289,6 +286,7 @@ def make(n, q, args):
def get(n, q, args): def get(n, q, args):
if args.test_id: if args.test_id:
print "Servers for test: " + test_id
run_instances = [] run_instances = []
instances = n.servers.list() instances = n.servers.list()
for instance in instances: for instance in instances:
@@ -297,9 +295,12 @@ def get(n, q, args):
run_instances.append(instance) run_instances.append(instance)
else: else:
run_instances = [] run_instances = {}
instances = n.servers.list() instances = n.servers.list()
for instance in instances: for instance in instances:
if 'ci_test_id' in instance.metadata: if 'ci_test_id' in instance.metadata:
run_instances.append(instance) if instance.metadata['ci_test_id'] not in run_instances:
run_instances[instance.metadata['ci_test_id']] = [instance.id]
else:
run_instances[instance.metadata['ci_test_id']].append(instance.id)
print run_instances print run_instances

View File

@@ -1,10 +1,13 @@
from build import debug, noop debug = False
even = True
def dprint(string): def dprint(string):
global even
global debug
if debug: if debug:
print '\033[94m' + str(string) + '\033[0m' if even:
print '\x1b[34m' + str(string) + '\x1b[0m'
even = False
def nprint(string): else:
if noop: print '\x1b[1;34m' + str(string) + '\x1b[0m'
print '\033[92m' + str(string) + '\033[0m' even = True