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:
Monty Taylor 2013-09-20 14:36:13 -07:00
parent c28c7c57bb
commit eef4f76011
7 changed files with 74 additions and 59 deletions

View File

@ -47,7 +47,8 @@ master_doc = 'index'
# General information about the project.
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
# |version| and |release|, also used in various other places throughout the

View File

@ -20,22 +20,18 @@
import sys
import os
import commands
import time
import subprocess
import traceback
import socket
import argparse
import utils
NOVA_USERNAME=os.environ['OS_USERNAME']
NOVA_PASSWORD=os.environ['OS_PASSWORD']
NOVA_URL=os.environ['OS_AUTH_URL']
NOVA_PROJECT_ID=os.environ['OS_TENANT_NAME']
NOVA_REGION_NAME=os.environ['OS_REGION_NAME']
NOVA_USERNAME = os.environ['OS_USERNAME']
NOVA_PASSWORD = os.environ['OS_PASSWORD']
NOVA_URL = os.environ['OS_AUTH_URL']
NOVA_PROJECT_ID = os.environ['OS_TENANT_NAME']
NOVA_REGION_NAME = os.environ['OS_REGION_NAME']
SCRIPT_DIR = os.path.dirname(sys.argv[0])
def get_client():
args = [NOVA_USERNAME, NOVA_PASSWORD, NOVA_PROJECT_ID, NOVA_URL]
kwargs = {}
@ -45,9 +41,11 @@ def get_client():
client = Client(*args, **kwargs)
return client
def print_dns(client, name):
for server in client.servers.list():
if server.name != name: continue
if server.name != name:
continue
ip4 = utils.get_public_ip(server)
ip6 = utils.get_public_ip(server, 6)
href = utils.get_href(server)
@ -57,13 +55,15 @@ def print_dns(client, name):
print
print ". ~root/rackdns-venv/bin/activate"
print
print ("rackdns rdns-create --name %s \\\n"
print (
"rackdns rdns-create --name %s \\\n"
" --data %s \\\n"
" --server-href %s \\\n"
" --ttl 3600" % (
server.name, ip6, href))
print
print ("rackdns rdns-create --name %s \\\n"
print (
"rackdns rdns-create --name %s \\\n"
" --data %s \\\n"
" --server-href %s \\\n"
" --ttl 3600" % (
@ -71,16 +71,19 @@ def print_dns(client, name):
print
print ". ~root/ci-launch/openstack-rs-nova.sh"
print
print ("rackdns record-create --name %s \\\n"
print (
"rackdns record-create --name %s \\\n"
" --type AAAA --data %s \\\n"
" --ttl 3600 openstack.org" % (
server.name, ip6))
print
print ("rackdns record-create --name %s \\\n"
print (
"rackdns record-create --name %s \\\n"
" --type A --data %s \\\n"
" --ttl 3600 openstack.org" % (
server.name, ip4))
def main():
parser = argparse.ArgumentParser()
parser.add_argument("name", help="server name")

View File

@ -20,23 +20,20 @@
import sys
import os
import commands
import time
import subprocess
import traceback
import socket
import argparse
import shutil
import dns
import utils
NOVA_USERNAME=os.environ['OS_USERNAME']
NOVA_PASSWORD=os.environ['OS_PASSWORD']
NOVA_URL=os.environ['OS_AUTH_URL']
NOVA_PROJECT_ID=os.environ['OS_TENANT_NAME']
NOVA_REGION_NAME=os.environ['OS_REGION_NAME']
IPV6=os.environ.get('IPV6', '0') is 1
NOVA_USERNAME = os.environ['OS_USERNAME']
NOVA_PASSWORD = os.environ['OS_PASSWORD']
NOVA_URL = os.environ['OS_AUTH_URL']
NOVA_PROJECT_ID = os.environ['OS_TENANT_NAME']
NOVA_REGION_NAME = os.environ['OS_REGION_NAME']
IPV6 = os.environ.get('IPV6', '0') is 1
SCRIPT_DIR = os.path.dirname(sys.argv[0])
@ -53,9 +50,9 @@ def get_client():
client = Client(*args, **kwargs)
return client
def bootstrap_server(server, admin_pass, key, cert, environment, name,
salt_priv, salt_pub, puppetmaster):
client = server.manager.api
ip = utils.get_public_ip(server)
if not ip:
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']:
ssh_client = utils.ssh_connect(ip, username, ssh_kwargs, timeout=600)
if ssh_client: break
if ssh_client:
break
if not ssh_client:
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')
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/private_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 0755 /var/lib/puppet/ssl/public_keys")
if salt_pub and salt_priv:
# Assuming salt-master is running on the puppetmaster
shutil.copyfile(salt_pub,
@ -129,6 +126,7 @@ def bootstrap_server(server, admin_pass, key, cert, environment, name,
ssh_client.ssh("reboot")
def build_server(
client, name, image, flavor, cert, environment, salt, puppetmaster):
key = None
@ -143,17 +141,18 @@ def build_server(
create_kwargs['key_name'] = key_name
try:
server = client.servers.create(**create_kwargs)
except Exception, real_error:
except Exception:
try:
kp.delete()
except Exception, delete_error:
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)
salt_priv, salt_pub = utils.add_salt_keypair(
SALT_MASTER_PKI, name, 2048)
try:
admin_pass = server.adminPass
server = utils.wait_for_resource(server)
@ -164,15 +163,16 @@ def build_server(
server.accessIPv6))
if key:
kp.delete()
except Exception, real_error:
except Exception:
try:
utils.delete_server(server)
except Exception, delete_error:
except Exception:
print "Exception encountered deleting server:"
traceback.print_exc()
# Raise the important exception that started this
raise
def main():
parser = argparse.ArgumentParser()
parser.add_argument("name", help="server name")

View File

@ -22,6 +22,7 @@ import sys
import paramiko
class SSHClient(object):
def __init__(self, ip, username, password=None, pkey=None):
client = paramiko.SSHClient()
@ -48,5 +49,3 @@ class SSHClient(object):
ftp = self.client.open_sftp()
ftp.put(source, dest)
ftp.close()

View File

@ -34,6 +34,7 @@ import salt.crypt
from sshclient import SSHClient
def iterate_timeout(max_seconds, purpose):
start = time.time()
count = 0
@ -66,6 +67,8 @@ def get_client(provider):
return client
extension_cache = {}
def get_extensions(client):
global extension_cache
cache = extension_cache.get(client)
@ -79,11 +82,13 @@ def get_extensions(client):
extension_cache[client] = extensions
return extensions
def get_flavor(client, 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))
return flavors[0]
def get_public_ip(server, version=4):
if 'os-floating-ips' in get_extensions(server.manager.api):
for addr in server.manager.api.floating_ips.list():
@ -92,18 +97,21 @@ def get_public_ip(server, version=4):
for addr in server.addresses.get('public', []):
if type(addr) == type(u''): # Rackspace/openstack 1.0
return addr
if addr['version'] == version: #Rackspace/openstack 1.1
if addr['version'] == version: # Rackspace/openstack 1.1
return addr['addr']
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 None
def get_href(server):
for link in server.links:
if link['rel'] == 'self':
return link['href']
def add_public_ip(server):
ip = server.manager.api.floating_ips.create()
server.add_floating_ip(ip)
@ -120,12 +128,14 @@ def add_public_ip(server):
print 'ip has been added'
return
def add_keypair(client, name):
key = paramiko.RSAKey.generate(2048)
public_key = key.get_name() + ' ' + key.get_base64()
kp = client.keypairs.create(name, public_key)
return key, kp
def add_salt_keypair(keydir, keyname, keysize=2048):
'''
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)
return priv_key, pub_key
def wait_for_resource(wait_resource):
last_progress = 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
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
last_progress = resource.progress
elif last_status != resource.status:
@ -169,6 +181,7 @@ def wait_for_resource(wait_resource):
if resource.status == 'ACTIVE':
return resource
def ssh_connect(ip, username, connect_kwargs={}, timeout=60):
# HPcloud may return errno 111 for about 30 seconds after adding the IP
for count in iterate_timeout(timeout, "ssh access"):
@ -184,6 +197,7 @@ def ssh_connect(ip, username, connect_kwargs={}, timeout=60):
return client
return None
def delete_server(server):
try:
if 'os-floating-ips' in get_extensions(server.manager.api):

View File

@ -16,14 +16,13 @@
import argparse
import os
import sys
import yaml
import tempfile
import pwd
import grp
# 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):
for c in u"\u000a\u000d\u001c\u001d\u001e\u0085\u2028\u2029":
if c in value:

View File

@ -19,8 +19,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import jenkins
import urllib
import urllib2
import urlparse
from pprint import pprint
@ -40,6 +38,7 @@ from myjenkins import Jenkins as DGJenkins
JOB_NAME = 'test-job'
NODE_NAME = 'test-node'
class JenkinsTest(object):
def __init__(self):
self.config = ConfigParser.ConfigParser()