Clean up flake8 issues before switch
In anticipation of swtiching to flake8 as part of the removal of pyflakes jobs, clean up a few flake8 errors so that we don't have to ignore as many things. Change-Id: Idb8466bb3194904d84e17dd3f2a7c32aff13788c
This commit is contained in:
parent
c28c7c57bb
commit
eef4f76011
@ -47,7 +47,8 @@ master_doc = 'index'
|
|||||||
|
|
||||||
# General information about the project.
|
# General information about the project.
|
||||||
project = u'OpenStack Project Infrastructure'
|
project = u'OpenStack Project Infrastructure'
|
||||||
copyright = u'2012-2013, OpenStack Infastructure Team - see git repo for details'
|
copyright = (u'2012-2013, OpenStack Infastructure Team'
|
||||||
|
' - see git repo for details')
|
||||||
|
|
||||||
# The version info for the project you're documenting, acts as replacement for
|
# The version info for the project you're documenting, acts as replacement for
|
||||||
# |version| and |release|, also used in various other places throughout the
|
# |version| and |release|, also used in various other places throughout the
|
||||||
|
@ -20,11 +20,6 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import commands
|
|
||||||
import time
|
|
||||||
import subprocess
|
|
||||||
import traceback
|
|
||||||
import socket
|
|
||||||
import argparse
|
import argparse
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
@ -36,6 +31,7 @@ NOVA_REGION_NAME=os.environ['OS_REGION_NAME']
|
|||||||
|
|
||||||
SCRIPT_DIR = os.path.dirname(sys.argv[0])
|
SCRIPT_DIR = os.path.dirname(sys.argv[0])
|
||||||
|
|
||||||
|
|
||||||
def get_client():
|
def get_client():
|
||||||
args = [NOVA_USERNAME, NOVA_PASSWORD, NOVA_PROJECT_ID, NOVA_URL]
|
args = [NOVA_USERNAME, NOVA_PASSWORD, NOVA_PROJECT_ID, NOVA_URL]
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
@ -45,9 +41,11 @@ def get_client():
|
|||||||
client = Client(*args, **kwargs)
|
client = Client(*args, **kwargs)
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
|
||||||
def print_dns(client, name):
|
def print_dns(client, name):
|
||||||
for server in client.servers.list():
|
for server in client.servers.list():
|
||||||
if server.name != name: continue
|
if server.name != name:
|
||||||
|
continue
|
||||||
ip4 = utils.get_public_ip(server)
|
ip4 = utils.get_public_ip(server)
|
||||||
ip6 = utils.get_public_ip(server, 6)
|
ip6 = utils.get_public_ip(server, 6)
|
||||||
href = utils.get_href(server)
|
href = utils.get_href(server)
|
||||||
@ -57,13 +55,15 @@ def print_dns(client, name):
|
|||||||
print
|
print
|
||||||
print ". ~root/rackdns-venv/bin/activate"
|
print ". ~root/rackdns-venv/bin/activate"
|
||||||
print
|
print
|
||||||
print ("rackdns rdns-create --name %s \\\n"
|
print (
|
||||||
|
"rackdns rdns-create --name %s \\\n"
|
||||||
" --data %s \\\n"
|
" --data %s \\\n"
|
||||||
" --server-href %s \\\n"
|
" --server-href %s \\\n"
|
||||||
" --ttl 3600" % (
|
" --ttl 3600" % (
|
||||||
server.name, ip6, href))
|
server.name, ip6, href))
|
||||||
print
|
print
|
||||||
print ("rackdns rdns-create --name %s \\\n"
|
print (
|
||||||
|
"rackdns rdns-create --name %s \\\n"
|
||||||
" --data %s \\\n"
|
" --data %s \\\n"
|
||||||
" --server-href %s \\\n"
|
" --server-href %s \\\n"
|
||||||
" --ttl 3600" % (
|
" --ttl 3600" % (
|
||||||
@ -71,16 +71,19 @@ def print_dns(client, name):
|
|||||||
print
|
print
|
||||||
print ". ~root/ci-launch/openstack-rs-nova.sh"
|
print ". ~root/ci-launch/openstack-rs-nova.sh"
|
||||||
print
|
print
|
||||||
print ("rackdns record-create --name %s \\\n"
|
print (
|
||||||
|
"rackdns record-create --name %s \\\n"
|
||||||
" --type AAAA --data %s \\\n"
|
" --type AAAA --data %s \\\n"
|
||||||
" --ttl 3600 openstack.org" % (
|
" --ttl 3600 openstack.org" % (
|
||||||
server.name, ip6))
|
server.name, ip6))
|
||||||
print
|
print
|
||||||
print ("rackdns record-create --name %s \\\n"
|
print (
|
||||||
|
"rackdns record-create --name %s \\\n"
|
||||||
" --type A --data %s \\\n"
|
" --type A --data %s \\\n"
|
||||||
" --ttl 3600 openstack.org" % (
|
" --ttl 3600 openstack.org" % (
|
||||||
server.name, ip4))
|
server.name, ip4))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("name", help="server name")
|
parser.add_argument("name", help="server name")
|
||||||
|
@ -20,11 +20,8 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import commands
|
|
||||||
import time
|
import time
|
||||||
import subprocess
|
|
||||||
import traceback
|
import traceback
|
||||||
import socket
|
|
||||||
import argparse
|
import argparse
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
@ -53,9 +50,9 @@ def get_client():
|
|||||||
client = Client(*args, **kwargs)
|
client = Client(*args, **kwargs)
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
|
||||||
def bootstrap_server(server, admin_pass, key, cert, environment, name,
|
def bootstrap_server(server, admin_pass, key, cert, environment, name,
|
||||||
salt_priv, salt_pub, puppetmaster):
|
salt_priv, salt_pub, puppetmaster):
|
||||||
client = server.manager.api
|
|
||||||
ip = utils.get_public_ip(server)
|
ip = utils.get_public_ip(server)
|
||||||
if not ip:
|
if not ip:
|
||||||
raise Exception("Unable to find public ip of server")
|
raise Exception("Unable to find public ip of server")
|
||||||
@ -68,7 +65,8 @@ def bootstrap_server(server, admin_pass, key, cert, environment, name,
|
|||||||
|
|
||||||
for username in ['root', 'ubuntu']:
|
for username in ['root', 'ubuntu']:
|
||||||
ssh_client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600)
|
ssh_client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600)
|
||||||
if ssh_client: break
|
if ssh_client:
|
||||||
|
break
|
||||||
|
|
||||||
if not ssh_client:
|
if not ssh_client:
|
||||||
raise Exception("Unable to log in via SSH")
|
raise Exception("Unable to log in via SSH")
|
||||||
@ -89,7 +87,7 @@ def bootstrap_server(server, admin_pass, key, cert, environment, name,
|
|||||||
'install_puppet.sh')
|
'install_puppet.sh')
|
||||||
ssh_client.ssh('bash -x install_puppet.sh')
|
ssh_client.ssh('bash -x install_puppet.sh')
|
||||||
|
|
||||||
certname = cert[:0-len('.pem')]
|
certname = cert[:(0 - len('.pem'))]
|
||||||
ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/certs")
|
ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/certs")
|
||||||
ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/private_keys")
|
ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/private_keys")
|
||||||
ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/public_keys")
|
ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/public_keys")
|
||||||
@ -99,7 +97,6 @@ def bootstrap_server(server, admin_pass, key, cert, environment, name,
|
|||||||
ssh_client.ssh("chmod 0750 /var/lib/puppet/ssl/private_keys")
|
ssh_client.ssh("chmod 0750 /var/lib/puppet/ssl/private_keys")
|
||||||
ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/public_keys")
|
ssh_client.ssh("chmod 0755 /var/lib/puppet/ssl/public_keys")
|
||||||
|
|
||||||
|
|
||||||
if salt_pub and salt_priv:
|
if salt_pub and salt_priv:
|
||||||
# Assuming salt-master is running on the puppetmaster
|
# Assuming salt-master is running on the puppetmaster
|
||||||
shutil.copyfile(salt_pub,
|
shutil.copyfile(salt_pub,
|
||||||
@ -129,6 +126,7 @@ def bootstrap_server(server, admin_pass, key, cert, environment, name,
|
|||||||
|
|
||||||
ssh_client.ssh("reboot")
|
ssh_client.ssh("reboot")
|
||||||
|
|
||||||
|
|
||||||
def build_server(
|
def build_server(
|
||||||
client, name, image, flavor, cert, environment, salt, puppetmaster):
|
client, name, image, flavor, cert, environment, salt, puppetmaster):
|
||||||
key = None
|
key = None
|
||||||
@ -143,17 +141,18 @@ def build_server(
|
|||||||
create_kwargs['key_name'] = key_name
|
create_kwargs['key_name'] = key_name
|
||||||
try:
|
try:
|
||||||
server = client.servers.create(**create_kwargs)
|
server = client.servers.create(**create_kwargs)
|
||||||
except Exception, real_error:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
kp.delete()
|
kp.delete()
|
||||||
except Exception, delete_error:
|
except Exception:
|
||||||
print "Exception encountered deleting keypair:"
|
print "Exception encountered deleting keypair:"
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
raise
|
raise
|
||||||
|
|
||||||
salt_priv, salt_pub = (None, None)
|
salt_priv, salt_pub = (None, None)
|
||||||
if salt:
|
if salt:
|
||||||
salt_priv, salt_pub = utils.add_salt_keypair(SALT_MASTER_PKI, name, 2048)
|
salt_priv, salt_pub = utils.add_salt_keypair(
|
||||||
|
SALT_MASTER_PKI, name, 2048)
|
||||||
try:
|
try:
|
||||||
admin_pass = server.adminPass
|
admin_pass = server.adminPass
|
||||||
server = utils.wait_for_resource(server)
|
server = utils.wait_for_resource(server)
|
||||||
@ -164,15 +163,16 @@ def build_server(
|
|||||||
server.accessIPv6))
|
server.accessIPv6))
|
||||||
if key:
|
if key:
|
||||||
kp.delete()
|
kp.delete()
|
||||||
except Exception, real_error:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
utils.delete_server(server)
|
utils.delete_server(server)
|
||||||
except Exception, delete_error:
|
except Exception:
|
||||||
print "Exception encountered deleting server:"
|
print "Exception encountered deleting server:"
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
# Raise the important exception that started this
|
# Raise the important exception that started this
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("name", help="server name")
|
parser.add_argument("name", help="server name")
|
||||||
|
@ -22,6 +22,7 @@ import sys
|
|||||||
|
|
||||||
import paramiko
|
import paramiko
|
||||||
|
|
||||||
|
|
||||||
class SSHClient(object):
|
class SSHClient(object):
|
||||||
def __init__(self, ip, username, password=None, pkey=None):
|
def __init__(self, ip, username, password=None, pkey=None):
|
||||||
client = paramiko.SSHClient()
|
client = paramiko.SSHClient()
|
||||||
@ -48,5 +49,3 @@ class SSHClient(object):
|
|||||||
ftp = self.client.open_sftp()
|
ftp = self.client.open_sftp()
|
||||||
ftp.put(source, dest)
|
ftp.put(source, dest)
|
||||||
ftp.close()
|
ftp.close()
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ import salt.crypt
|
|||||||
|
|
||||||
from sshclient import SSHClient
|
from sshclient import SSHClient
|
||||||
|
|
||||||
|
|
||||||
def iterate_timeout(max_seconds, purpose):
|
def iterate_timeout(max_seconds, purpose):
|
||||||
start = time.time()
|
start = time.time()
|
||||||
count = 0
|
count = 0
|
||||||
@ -66,6 +67,8 @@ def get_client(provider):
|
|||||||
return client
|
return client
|
||||||
|
|
||||||
extension_cache = {}
|
extension_cache = {}
|
||||||
|
|
||||||
|
|
||||||
def get_extensions(client):
|
def get_extensions(client):
|
||||||
global extension_cache
|
global extension_cache
|
||||||
cache = extension_cache.get(client)
|
cache = extension_cache.get(client)
|
||||||
@ -79,11 +82,13 @@ def get_extensions(client):
|
|||||||
extension_cache[client] = extensions
|
extension_cache[client] = extensions
|
||||||
return extensions
|
return extensions
|
||||||
|
|
||||||
|
|
||||||
def get_flavor(client, min_ram):
|
def get_flavor(client, min_ram):
|
||||||
flavors = [f for f in client.flavors.list() if f.ram >= min_ram]
|
flavors = [f for f in client.flavors.list() if f.ram >= min_ram]
|
||||||
flavors.sort(lambda a, b: cmp(a.ram, b.ram))
|
flavors.sort(lambda a, b: cmp(a.ram, b.ram))
|
||||||
return flavors[0]
|
return flavors[0]
|
||||||
|
|
||||||
|
|
||||||
def get_public_ip(server, version=4):
|
def get_public_ip(server, version=4):
|
||||||
if 'os-floating-ips' in get_extensions(server.manager.api):
|
if 'os-floating-ips' in get_extensions(server.manager.api):
|
||||||
for addr in server.manager.api.floating_ips.list():
|
for addr in server.manager.api.floating_ips.list():
|
||||||
@ -95,15 +100,18 @@ def get_public_ip(server, version=4):
|
|||||||
if addr['version'] == version: # Rackspace/openstack 1.1
|
if addr['version'] == version: # Rackspace/openstack 1.1
|
||||||
return addr['addr']
|
return addr['addr']
|
||||||
for addr in server.addresses.get('private', []):
|
for addr in server.addresses.get('private', []):
|
||||||
if addr['version'] == version and not addr['addr'].startswith('10.'): #HPcloud
|
# HP Cloud
|
||||||
|
if addr['version'] == version and not addr['addr'].startswith('10.'):
|
||||||
return addr['addr']
|
return addr['addr']
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_href(server):
|
def get_href(server):
|
||||||
for link in server.links:
|
for link in server.links:
|
||||||
if link['rel'] == 'self':
|
if link['rel'] == 'self':
|
||||||
return link['href']
|
return link['href']
|
||||||
|
|
||||||
|
|
||||||
def add_public_ip(server):
|
def add_public_ip(server):
|
||||||
ip = server.manager.api.floating_ips.create()
|
ip = server.manager.api.floating_ips.create()
|
||||||
server.add_floating_ip(ip)
|
server.add_floating_ip(ip)
|
||||||
@ -120,12 +128,14 @@ def add_public_ip(server):
|
|||||||
print 'ip has been added'
|
print 'ip has been added'
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def add_keypair(client, name):
|
def add_keypair(client, name):
|
||||||
key = paramiko.RSAKey.generate(2048)
|
key = paramiko.RSAKey.generate(2048)
|
||||||
public_key = key.get_name() + ' ' + key.get_base64()
|
public_key = key.get_name() + ' ' + key.get_base64()
|
||||||
kp = client.keypairs.create(name, public_key)
|
kp = client.keypairs.create(name, public_key)
|
||||||
return key, kp
|
return key, kp
|
||||||
|
|
||||||
|
|
||||||
def add_salt_keypair(keydir, keyname, keysize=2048):
|
def add_salt_keypair(keydir, keyname, keysize=2048):
|
||||||
'''
|
'''
|
||||||
Generate a key pair for use with Salt
|
Generate a key pair for use with Salt
|
||||||
@ -145,6 +155,7 @@ def add_salt_keypair(keydir, keyname, keysize=2048):
|
|||||||
pub_key = '{0}.pub'.format(path)
|
pub_key = '{0}.pub'.format(path)
|
||||||
return priv_key, pub_key
|
return priv_key, pub_key
|
||||||
|
|
||||||
|
|
||||||
def wait_for_resource(wait_resource):
|
def wait_for_resource(wait_resource):
|
||||||
last_progress = None
|
last_progress = None
|
||||||
last_status = None
|
last_status = None
|
||||||
@ -160,7 +171,8 @@ def wait_for_resource(wait_resource):
|
|||||||
|
|
||||||
# In Rackspace v1.0, there is no progress attribute while queued
|
# In Rackspace v1.0, there is no progress attribute while queued
|
||||||
if hasattr(resource, 'progress'):
|
if hasattr(resource, 'progress'):
|
||||||
if last_progress != resource.progress or last_status != resource.status:
|
if (last_progress != resource.progress
|
||||||
|
or last_status != resource.status):
|
||||||
print resource.status, resource.progress
|
print resource.status, resource.progress
|
||||||
last_progress = resource.progress
|
last_progress = resource.progress
|
||||||
elif last_status != resource.status:
|
elif last_status != resource.status:
|
||||||
@ -169,6 +181,7 @@ def wait_for_resource(wait_resource):
|
|||||||
if resource.status == 'ACTIVE':
|
if resource.status == 'ACTIVE':
|
||||||
return resource
|
return resource
|
||||||
|
|
||||||
|
|
||||||
def ssh_connect(ip, username, connect_kwargs={}, timeout=60):
|
def ssh_connect(ip, username, connect_kwargs={}, timeout=60):
|
||||||
# HPcloud may return errno 111 for about 30 seconds after adding the IP
|
# HPcloud may return errno 111 for about 30 seconds after adding the IP
|
||||||
for count in iterate_timeout(timeout, "ssh access"):
|
for count in iterate_timeout(timeout, "ssh access"):
|
||||||
@ -184,6 +197,7 @@ def ssh_connect(ip, username, connect_kwargs={}, timeout=60):
|
|||||||
return client
|
return client
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def delete_server(server):
|
def delete_server(server):
|
||||||
try:
|
try:
|
||||||
if 'os-floating-ips' in get_extensions(server.manager.api):
|
if 'os-floating-ips' in get_extensions(server.manager.api):
|
||||||
|
@ -16,14 +16,13 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import yaml
|
import yaml
|
||||||
import tempfile
|
import tempfile
|
||||||
import pwd
|
import pwd
|
||||||
import grp
|
import grp
|
||||||
|
|
||||||
# from:
|
# from:
|
||||||
# http://stackoverflow.com/questions/8640959/how-can-i-control-what-scalar-form-pyyaml-uses-for-my-data
|
# http://stackoverflow.com/questions/8640959/how-can-i-control-what-scalar-form-pyyaml-uses-for-my-data flake8: noqa
|
||||||
def should_use_block(value):
|
def should_use_block(value):
|
||||||
for c in u"\u000a\u000d\u001c\u001d\u001e\u0085\u2028\u2029":
|
for c in u"\u000a\u000d\u001c\u001d\u001e\u0085\u2028\u2029":
|
||||||
if c in value:
|
if c in value:
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import jenkins
|
|
||||||
import urllib
|
|
||||||
import urllib2
|
import urllib2
|
||||||
import urlparse
|
import urlparse
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
@ -40,6 +38,7 @@ from myjenkins import Jenkins as DGJenkins
|
|||||||
JOB_NAME = 'test-job'
|
JOB_NAME = 'test-job'
|
||||||
NODE_NAME = 'test-node'
|
NODE_NAME = 'test-node'
|
||||||
|
|
||||||
|
|
||||||
class JenkinsTest(object):
|
class JenkinsTest(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.config = ConfigParser.ConfigParser()
|
self.config = ConfigParser.ConfigParser()
|
||||||
|
Loading…
Reference in New Issue
Block a user