def check_machine(jenkins, client, machine, error_counts): try: server = client.servers.get(machine.external_id) except: print "Unable to get server detail, will retry" traceback.print_exc() return if server.status == "ACTIVE": ip = utils.get_public_ip(server) if not ip and "os-floating-ips" in utils.get_extensions(client): utils.add_public_ip(server) ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") machine.ip = ip print "Machine %s is running, testing ssh" % machine.id if utils.ssh_connect(ip, "jenkins"): print "Adding machine %s to Jenkins" % machine.id create_jenkins_node(jenkins, machine) print "Machine %s is ready" % machine.id machine.state = vmdatabase.READY return elif not server.status.startswith("BUILD"): count = error_counts.get(machine.id, 0) count += 1 error_counts[machine.id] = count print "Machine %s is in error %s (%s/5)" % (machine.id, server.status, count) if count >= 5: raise Exception("Too many errors querying machine %s" % machine.id) else: if time.time() - machine.state_time >= ABANDON_TIMEOUT: raise Exception("Waited too long for machine %s" % machine.id)
def check_machine(jenkins, client, machine, error_counts): try: server = client.servers.get(machine.external_id) except: print "Unable to get server detail, will retry" traceback.print_exc() return if server.status == 'ACTIVE': ip = utils.get_public_ip(server) if not ip and 'os-floating-ips' in utils.get_extensions(client): utils.add_public_ip(server) ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") machine.ip = ip print "Machine %s is running, testing ssh" % machine.id if utils.ssh_connect(ip, 'jenkins'): print "Adding machine %s to Jenkins" % machine.id create_jenkins_node(jenkins, machine) print "Machine %s is ready" % machine.id machine.state = vmdatabase.READY return elif not server.status.startswith('BUILD'): count = error_counts.get(machine.id, 0) count += 1 error_counts[machine.id] = count print "Machine %s is in error %s (%s/5)" % (machine.id, server.status, count) if count >= 5: raise Exception("Too many errors querying machine %s" % machine.id) else: if time.time() - machine.state_time >= ABANDON_TIMEOUT: raise Exception("Waited too long for machine %s" % machine.id)
def build_server( client, name, image, flavor, cert, environment, puppetmaster, volume, keep, net_label, floating_ip_pool): key = None server = None create_kwargs = dict(image=image, flavor=flavor, name=name) if net_label: nics = [] for net in client.networks.list(): if net.label == net_label: nics.append({'net-id': net.id}) create_kwargs['nics'] = nics key_name = 'launch-%i' % (time.time()) if 'os-keypairs' in utils.get_extensions(client): print "Adding keypair" key, kp = utils.add_keypair(client, key_name) create_kwargs['key_name'] = key_name try: server = client.servers.create(**create_kwargs) except Exception: try: kp.delete() except Exception: print "Exception encountered deleting keypair:" traceback.print_exc() raise try: admin_pass = server.adminPass server = utils.wait_for_resource(server) if volume: vobj = client.volumes.create_server_volume( server.id, volume, None) if not vobj: raise Exception("Couldn't attach volume") bootstrap_server(server, admin_pass, key, cert, environment, name, puppetmaster, volume, floating_ip_pool) print('UUID=%s\nIPV4=%s\nIPV6=%s\n' % (server.id, server.accessIPv4, server.accessIPv6)) if key: kp.delete() except Exception: try: if keep: print "Server failed to build, keeping as requested." else: utils.delete_server(server) except Exception: print "Exception encountered deleting server:" traceback.print_exc() # Raise the important exception that started this raise
def build_image(provider, client, base_image, image, flavor, name, branches, timestamp): print "Building image %s" % name create_kwargs = dict(image=image, flavor=flavor, name=name) key = None key_name = '%sdevstack-%i' % (DEVSTACK_GATE_PREFIX, time.time()) if 'os-keypairs' in utils.get_extensions(client): print "Adding keypair" key, kp = utils.add_keypair(client, key_name) create_kwargs['key_name'] = key_name server = client.servers.create(**create_kwargs) snap_image = base_image.newSnapshotImage(name=name, version=timestamp, external_id=None, server_external_id=server.id) admin_pass = server.adminPass try: print "Waiting for server ID %s" % server.id server = utils.wait_for_resource(server) bootstrap_server(provider, server, admin_pass, key) configure_server(server, branches) remote_snap_image = snapshot_server(client, server, name) snap_image.external_id = remote_snap_image.id snap_image.state = vmdatabase.READY # We made the snapshot, try deleting the server, but it's okay # if we fail. The reap script will find it and try again. try: utils.delete_server(server) except: print "Exception encountered deleting server:" traceback.print_exc() except Exception: # Something went wrong, try our best to mark the server in error # then delete the server, then delete the db record for it. # If any of this fails, the reap script should catch it. But # having correct info in the DB will help it do its job faster. try: snap_image.state = vmdatabase.ERROR try: utils.delete_server(server) snap_image.delete() except Exception: print "Exception encountered deleting server:" traceback.print_exc() except Exception: print "Exception encountered marking server in error:" traceback.print_exc() # Raise the important exception that started this raise
def bootstrap_server(provider, server, admin_pass, key): client = server.manager.api ip = utils.get_public_ip(server) if not ip and "os-floating-ips" in utils.get_extensions(client): utils.add_public_ip(server) ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") ssh_kwargs = {} if key: ssh_kwargs["pkey"] = key else: ssh_kwargs["password"] = admin_pass for username in ["root", "ubuntu"]: client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600) if client: break if not client: raise Exception("Unable to log in via SSH") # hpcloud can't reliably set the hostname gerrit_url = "https://review.openstack.org/p/openstack-infra/config.git" client.ssh("set hostname", "sudo hostname %s" % server.name) client.ssh( "get puppet repo deb", "sudo /usr/bin/wget " "http://apt.puppetlabs.com/puppetlabs-release-" "`lsb_release -c -s`.deb -O /root/puppet-repo.deb", ) client.ssh("install puppet repo deb", "sudo dpkg -i /root/puppet-repo.deb") client.ssh("update apt cache", "sudo apt-get update") client.ssh( "upgrading system packages", "sudo DEBIAN_FRONTEND=noninteractive apt-get " '--option "Dpkg::Options::=--force-confold"' " --assume-yes dist-upgrade", ) client.ssh( "install git and puppet", "sudo DEBIAN_FRONTEND=noninteractive apt-get " '--option "Dpkg::Options::=--force-confold"' " --assume-yes install git puppet", ) client.ssh("clone puppret repo", "sudo git clone %s /root/config" % gerrit_url) client.ssh("install puppet modules", "sudo /bin/bash /root/config/install_modules.sh") client.ssh( "run puppet", "sudo puppet apply --modulepath=/root/config/modules:" "/etc/puppet/modules " '-e "%s"' % PUPPET_CLASS, )
def build_server( client, name, image, flavor, cert, environment, puppetmaster, volume, keep): key = None server = None # BH: HARDCODE nics = [{'net-id': u'b25625cc-2f6b-48c2-b740-08e2b0503a19'}] create_kwargs = dict(image=image, flavor=flavor, name=name, nics=nics) key_name = 'launch-%i' % (time.time()) if 'os-keypairs' in utils.get_extensions(client): print "Adding keypair" key, kp = utils.add_keypair(client, key_name) create_kwargs['key_name'] = key_name try: server = client.servers.create(**create_kwargs) except Exception: try: kp.delete() except Exception: print "Exception encountered deleting keypair:" traceback.print_exc() raise try: admin_pass = server.adminPass server = utils.wait_for_resource(server) if volume: vobj = client.volumes.create_server_volume( server.id, volume, None) if not vobj: raise Exception("Couldn't attach volume") bootstrap_server(server, admin_pass, key, cert, environment, name, puppetmaster, volume) print('UUID=%s\nIPV4=%s\nIPV6=%s\n' % (server.id, server.accessIPv4, server.accessIPv6)) if key: kp.delete() except Exception: try: if keep: print "Server failed to build, keeping as requested." else: utils.delete_server(server) except Exception: print "Exception encountered deleting server:" traceback.print_exc() # Raise the important exception that started this raise
def build_image(provider, client, base_image, image, flavor, name, branches, timestamp): print "Building image %s" % name create_kwargs = dict(image=image, flavor=flavor, name=name) key = None key_name = '%sdevstack-%i' % (DEVSTACK_GATE_PREFIX, time.time()) if 'os-keypairs' in utils.get_extensions(client): print "Adding keypair" key, kp = utils.add_keypair(client, key_name) create_kwargs['key_name'] = key_name server = client.servers.create(**create_kwargs) snap_image = base_image.newSnapshotImage(name=name, version=timestamp, external_id=None, server_external_id=server.id) admin_pass = server.adminPass try: print "Waiting for server ID %s" % server.id server = utils.wait_for_resource(server) bootstrap_server(provider, server, admin_pass, key) configure_server(server, branches) remote_snap_image = snapshot_server(client, server, name) snap_image.external_id = remote_snap_image.id snap_image.state = vmdatabase.READY # We made the snapshot, try deleting the server, but it's okay # if we fail. The reap script will find it and try again. try: pass # XXX # utils.delete_server(server) except: print "Exception encountered deleting server:" traceback.print_exc() except Exception, real_error: # Something went wrong, try our best to mark the server in error # then delete the server, then delete the db record for it. # If any of this fails, the reap script should catch it. But # having correct info in the DB will help it do its job faster. try: snap_image.state = vmdatabase.ERROR try: utils.delete_server(server) snap_image.delete() except Exception, delete_error: print "Exception encountered deleting server:" traceback.print_exc() except Execption, database_error: print "Exception encountered marking server in error:" traceback.print_exc()
def bootstrap_server(provider, server, admin_pass, key): client = server.manager.api ip = utils.get_public_ip(server) if not ip and 'os-floating-ips' in utils.get_extensions(client): utils.add_public_ip(server) ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") ssh_kwargs = {} if key: ssh_kwargs['pkey'] = key else: ssh_kwargs['password'] = admin_pass for username in ['root', 'ubuntu']: client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600) if client: break if not client: raise Exception("Unable to log in via SSH") # hpcloud can't reliably set the hostname gerrit_url = 'https://review.openstack.org/p/openstack-infra/config.git' client.ssh("set hostname", "sudo hostname %s" % server.name) client.ssh( "get puppet repo deb", "sudo /usr/bin/wget " "http://apt.puppetlabs.com/puppetlabs-release-" "`lsb_release -c -s`.deb -O /root/puppet-repo.deb") client.ssh("install puppet repo deb", "sudo dpkg -i /root/puppet-repo.deb") client.ssh("update apt cache", "sudo apt-get update") client.ssh( "upgrading system packages", 'sudo DEBIAN_FRONTEND=noninteractive apt-get ' '--option "Dpkg::Options::=--force-confold"' ' --assume-yes dist-upgrade') client.ssh( "install git and puppet", 'sudo DEBIAN_FRONTEND=noninteractive apt-get ' '--option "Dpkg::Options::=--force-confold"' ' --assume-yes install git puppet') client.ssh("clone puppret repo", "sudo git clone %s /root/config" % gerrit_url) client.ssh("install puppet modules", "sudo /bin/bash /root/config/install_modules.sh") client.ssh( "run puppet", "sudo puppet apply --modulepath=/root/config/modules:" "/etc/puppet/modules " '-e "%s"' % PUPPET_CLASS)
def check_machine(jenkins, client, machine, error_counts, credentials_id): try: server = client.servers.get(machine.external_id) except: print "Unable to get server detail, will retry" traceback.print_exc() return if server.status == 'ACTIVE': ip = utils.get_public_ip(server) if not ip and 'os-floating-ips' in utils.get_extensions(client): utils.add_public_ip(server) ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") machine.ip = ip print "Machine %s is running, testing ssh" % machine.id if utils.ssh_connect(ip, 'jenkins'): if statsd: dt = int((time.time() - machine.state_time) * 1000) key = 'devstack.launch.%s' % machine.base_image.provider.name statsd.timing(key, dt) statsd.incr(key) print "Adding machine %s to Jenkins" % machine.id create_jenkins_node(jenkins, machine, credentials_id) print "Machine %s is ready" % machine.id machine.state = vmdatabase.READY utils.log.debug("Online ID: %s" % machine.id) return elif not server.status.startswith('BUILD'): count = error_counts.get(machine.id, 0) count += 1 error_counts[machine.id] = count print "Machine %s is in error %s (%s/5)" % (machine.id, server.status, count) if count >= 5: if statsd: statsd.incr('devstack.error.%s' % machine.base_image.provider.name) raise Exception("Too many errors querying machine %s" % machine.id) else: if time.time() - machine.state_time >= ABANDON_TIMEOUT: if statsd: statsd.incr('devstack.timeout.%s' % machine.base_image.provider.name) raise Exception("Waited too long for machine %s" % machine.id)
def check_machine(jenkins, client, machine, error_counts): try: server = client.servers.get(machine.external_id) except: print "Unable to get server detail, will retry" traceback.print_exc() return if server.status == 'ACTIVE': ip = utils.get_public_ip(server) if not ip and 'os-floating-ips' in utils.get_extensions(client): utils.add_public_ip(server) ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") machine.ip = ip print "Machine %s is running, testing ssh" % machine.id if utils.ssh_connect(ip, 'jenkins'): if statsd: dt = int((time.time() - machine.state_time) * 1000) key = 'devstack.launch.%s' % machine.base_image.provider.name statsd.timing(key, dt) statsd.incr(key) print "Adding machine %s to Jenkins" % machine.id create_jenkins_node(jenkins, machine) print "Machine %s is ready" % machine.id machine.state = vmdatabase.READY return elif not server.status.startswith('BUILD'): count = error_counts.get(machine.id, 0) count += 1 error_counts[machine.id] = count print "Machine %s is in error %s (%s/5)" % (machine.id, server.status, count) if count >= 5: if statsd: statsd.incr('devstack.error.%s' % machine.base_image.provider.name) raise Exception("Too many errors querying machine %s" % machine.id) else: if time.time() - machine.state_time >= ABANDON_TIMEOUT: if statsd: statsd.incr('devstack.timeout.%s' % machine.base_image.provider.name) raise Exception("Waited too long for machine %s" % machine.id)
def bootstrap_server(provider, server, admin_pass, key): client = server.manager.api ip = utils.get_public_ip(server) if not ip and 'os-floating-ips' in utils.get_extensions(client): utils.add_public_ip(server) ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") ssh_kwargs = {} if key: ssh_kwargs['pkey'] = key else: ssh_kwargs['password'] = admin_pass for username in ['root', 'ubuntu']: client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600) if client: break if not client: raise Exception("Unable to log in via SSH") # hpcloud can't reliably set the hostname gerrit_url = 'https://review.openstack.org/p/openstack/' \ 'openstack-ci-puppet.git' client.ssh("set hostname", "sudo hostname %s" % server.name) client.ssh("update apt cache", "sudo apt-get update") client.ssh( "upgrading system packages", 'sudo DEBIAN_FRONTEND=noninteractive apt-get ' '--option "Dpkg::Options::=--force-confold"' ' --assume-yes upgrade') client.ssh( "install git and puppet", 'sudo DEBIAN_FRONTEND=noninteractive apt-get ' '--option "Dpkg::Options::=--force-confold"' ' --assume-yes install git puppet') client.ssh("clone puppret repo", "sudo git clone %s /root/openstack-ci-puppet" % gerrit_url) client.ssh( "run puppet", "sudo puppet apply " "--modulepath=/root/openstack-ci-puppet/modules" "/root/openstack-ci-puppet/manifests/site.pp")
def build_server( client, name, image, flavor, cert, environment, salt, puppetmaster): key = None server = None create_kwargs = dict(image=image, flavor=flavor, name=name) key_name = 'launch-%i' % (time.time()) if 'os-keypairs' in utils.get_extensions(client): print "Adding keypair" key, kp = utils.add_keypair(client, key_name) create_kwargs['key_name'] = key_name try: server = client.servers.create(**create_kwargs) except Exception: try: kp.delete() except Exception: print "Exception encountered deleting keypair:" traceback.print_exc() raise salt_priv, salt_pub = (None, None) if salt: salt_priv, salt_pub = utils.add_salt_keypair( SALT_MASTER_PKI, name, 2048) try: admin_pass = server.adminPass server = utils.wait_for_resource(server) bootstrap_server(server, admin_pass, key, cert, environment, name, salt_priv, salt_pub, puppetmaster) print('UUID=%s\nIPV4=%s\nIPV6=%s\n' % (server.id, server.accessIPv4, server.accessIPv6)) if key: kp.delete() except Exception: try: utils.delete_server(server) except Exception: print "Exception encountered deleting server:" traceback.print_exc() # Raise the important exception that started this raise
def build_server(client, name, image, flavor, cert, environment): key = None server = None create_kwargs = dict(image=image, flavor=flavor, name=name) key_name = 'launch-%i' % (time.time()) if 'os-keypairs' in utils.get_extensions(client): print "Adding keypair" key, kp = utils.add_keypair(client, key_name) create_kwargs['key_name'] = key_name try: server = client.servers.create(**create_kwargs) except Exception, real_error: try: kp.delete() except Exception, delete_error: print "Exception encountered deleting keypair:" traceback.print_exc()
def build_server(client, name, image, flavor, cert, environment, salt, puppetmaster): key = None server = None create_kwargs = dict(image=image, flavor=flavor, name=name) key_name = 'launch-%i' % (time.time()) if 'os-keypairs' in utils.get_extensions(client): print "Adding keypair" key, kp = utils.add_keypair(client, key_name) create_kwargs['key_name'] = key_name try: server = client.servers.create(**create_kwargs) except Exception: try: kp.delete() except Exception: print "Exception encountered deleting keypair:" traceback.print_exc() raise salt_priv, salt_pub = (None, None) if salt: salt_priv, salt_pub = utils.add_salt_keypair(SALT_MASTER_PKI, name, 2048) try: admin_pass = server.adminPass server = utils.wait_for_resource(server) bootstrap_server(server, admin_pass, key, cert, environment, name, salt_priv, salt_pub, puppetmaster) print('UUID=%s\nIPV4=%s\nIPV6=%s\n' % (server.id, server.accessIPv4, server.accessIPv6)) if key: kp.delete() except Exception: try: utils.delete_server(server) except Exception: print "Exception encountered deleting server:" traceback.print_exc() # Raise the important exception that started this raise
def bootstrap_server(provider, server, admin_pass, key): client = server.manager.api ip = utils.get_public_ip(server) if not ip and 'os-floating-ips' in utils.get_extensions(client): utils.add_public_ip(server) ip = utils.get_public_ip(server) if not ip: raise Exception("Unable to find public ip of server") ssh_kwargs = {} if key: ssh_kwargs['pkey'] = key else: ssh_kwargs['password'] = admin_pass for username in ['root', 'ubuntu']: client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600) if client: break if not client: raise Exception("Unable to log in via SSH") # hpcloud can't reliably set the hostname gerrit_url = 'https://review.openstack.org/p/openstack/' \ 'openstack-ci-puppet.git' client.ssh("set hostname", "sudo hostname %s" % server.name) client.ssh("update apt cache", "sudo apt-get update") client.ssh("upgrading system packages", 'sudo DEBIAN_FRONTEND=noninteractive apt-get ' '--option "Dpkg::Options::=--force-confold"' ' --assume-yes upgrade') client.ssh("install git and puppet", 'sudo DEBIAN_FRONTEND=noninteractive apt-get ' '--option "Dpkg::Options::=--force-confold"' ' --assume-yes install git puppet') client.ssh("clone puppret repo", "sudo git clone %s /root/openstack-ci-puppet" % gerrit_url) client.ssh("run puppet", "sudo puppet apply " "--modulepath=/root/openstack-ci-puppet/modules" "/root/openstack-ci-puppet/manifests/site.pp")
def build_server(client, name, image, flavor, environment): key = None server = None create_kwargs = dict(image=image, flavor=flavor, name=name) if 'os-keypairs' in utils.get_extensions(client): create_kwargs['key_name'] = 'mordred' server = client.servers.create(**create_kwargs) try: admin_pass = server.adminPass server = utils.wait_for_resource(server) bootstrap_server(name, server, admin_pass, key, environment) except Exception, real_error: try: utils.delete_server(server) pass except Exception, delete_error: print "Exception encountered deleting server:" traceback.print_exc()
dst_dir: the folder where tfrecord will be placed. prefix: any string you want. num_split: any integer you want. """ src_image_dir = './segmentation_dataset/img' src_segmentation_dir = './segmentation_dataset/seg' dst_dir = './segmentation_dataset' prefix = 'train' num_split = 4 img_list = utils.list_getter(src_image_dir) shuffle(img_list) img_ext = utils.get_extensions(img_list) img_reader = utils.ImageReader(img_ext, channels=3) seg_reader = utils.ImageReader("png", channels=1) img_list_split = utils.divide_list(img_list, num_split) os.makedirs(dst_dir, exist_ok=True) def write_tfrecord(file_list, split_idx): if num_split == 1: dst_file_name = os.path.join(dst_dir, "%s.tfrecord" % prefix) else: dst_file_name = os.path.join( dst_dir, "%s-%03d-of-%03d.tfrecord" % (prefix, split_idx, num_split)) with tf.python_io.TFRecordWriter(dst_file_name) as tfrecord_writer: for image_filename in file_list: