Skip to content

Commit

Permalink
Fix mistypes and minor code style issues
Browse files Browse the repository at this point in the history
1. Fix mistypes, except interfaces
2. Fix old style classes (now inherit from object)
3. Fix single quoted docstrings
4. Redundant parenthesis
5. shadow builtins in locals (aka str or type as variable names)

Change-Id: Ie7c746c6e603472452766ba96cd94a6a3b232d6c
Closes-bug: #1517507
  • Loading branch information
penguinolog committed Nov 19, 2015
1 parent e307383 commit cc2ed26
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 35 deletions.
6 changes: 3 additions & 3 deletions devops/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def __init__(self, ssh):
def __enter__(self):
self.ssh.sudo_mode = True

def __exit__(self, type, value, traceback):
def __exit__(self, exc_type, value, traceback):
self.ssh.sudo_mode = False

def __init__(self, host, port=22, username=None, password=None,
Expand Down Expand Up @@ -433,15 +433,15 @@ def xmlrpctoken(uri, login, password):
try:
return server.login(login, password)
except Exception:
raise AuthenticationError("Error occured while login process")
raise AuthenticationError("Error occurred while login process")


def xmlrpcmethod(uri, method):
server = xmlrpclib.Server(uri)
try:
return getattr(server, method)
except Exception:
raise AttributeError("Error occured while getting server method")
raise AttributeError("Error occurred while getting server method")


def generate_mac():
Expand Down
2 changes: 1 addition & 1 deletion devops/helpers/node_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def admin_wait_bootstrap(puppet_timeout, env):
"""

print("Waiting while bootstrapping is in progress")
print("Puppet timeout set in {0}").format(puppet_timeout)
print("Puppet timeout set in {0}".format(puppet_timeout))
wait(
lambda: not
get_admin_remote(env).execute(
Expand Down
6 changes: 3 additions & 3 deletions devops/helpers/ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def get_ntp(remote, node_name='node', admin_ip=None):
cls.node_name = node_name
cls.peers = []

# Get IP of a server from which the time will be syncronized.
# Get IP of a server from which the time will be synchronized.
cmd = "awk '/^server/ && $2 !~ /127.*/ {print $2}' /etc/ntp.conf"
cls.server = remote.execute(cmd)['stdout'][0]

Expand Down Expand Up @@ -222,12 +222,12 @@ def wait_peer(self, interval=8, timeout=600):
if (abs(offset) > 500) or (abs(jitter) > 500):
return self.is_connected

# 2. remote should be marked whith tally '*'
# 2. remote should be marked with tally '*'
if remote[0] != '*':
continue

# 3. reachability bit array should have '1' at least in
# two lower bits as the last two sussesful checks
# two lower bits as the last two successful checks
if reach & 3 == 3:
self.is_connected = True
return self.is_connected
Expand Down
2 changes: 1 addition & 1 deletion devops/helpers/scancodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def iterable(a):


def from_string(s):
"from_string(s) - Convert string of chars into string of scancodes."
"""from_string(s) - Convert string of chars into string of scancodes."""

scancodes = []

Expand Down
2 changes: 1 addition & 1 deletion devops/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DriverModel(models.Model):
_driver = None
created = models.DateTimeField(auto_now_add=True, default=datetime.utcnow)

class Meta:
class Meta(object):
abstract = True

@classmethod
Expand Down
12 changes: 6 additions & 6 deletions devops/models/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


class Environment(DriverModel):
class Meta:
class Meta(object):
db_table = 'devops_environment'

name = models.CharField(max_length=255, unique=True, null=False)
Expand Down Expand Up @@ -157,7 +157,7 @@ def revert(self, name=None, destroy=True, flag=True):
if destroy:
for node in self.get_nodes():
node.destroy(verbose=False)
if (flag and not self.has_snapshot(name)):
if flag and not self.has_snapshot(name):
raise Exception("some nodes miss snapshot,"
" test should be interrupted")
for node in self.get_nodes():
Expand All @@ -175,7 +175,7 @@ def synchronize_all(cls):
# on domains that are outside the scope of devops, if anything this
# should cause domains to be imported into db instead of undefined.
# It also leaves network and volumes around too
# Disabled untill a safer implmentation arrives
# Disabled until a safer implementation arrives

# Undefine domains without devops nodes
#
Expand Down Expand Up @@ -306,9 +306,9 @@ def describe_admin_node(self, name, networks, boot_from='cdrom',

if self.os_image is None:
iso = iso_path or settings.ISO_PATH
self.add_empty_volume(node, name + '-system',
capacity=settings.ADMIN_NODE_VOLUME_SIZE
* 1024 ** 3)
self.add_empty_volume(
node, name + '-system',
capacity=settings.ADMIN_NODE_VOLUME_SIZE * 1024 ** 3)
self.add_empty_volume(
node,
name + '-iso',
Expand Down
8 changes: 4 additions & 4 deletions devops/models/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


class Network(DriverModel):
class Meta:
class Meta(object):
unique_together = ('name', 'environment')
db_table = 'devops_network'

Expand Down Expand Up @@ -213,7 +213,7 @@ def create_networks(cls, environment, network_names=None,


class DiskDevice(models.Model):
class Meta:
class Meta(object):
db_table = 'devops_diskdevice'

node = models.ForeignKey('Node', null=False)
Expand All @@ -237,7 +237,7 @@ def node_attach_volume(cls, node, volume, device='disk', type='file',


class Interface(models.Model):
class Meta:
class Meta(object):
db_table = 'devops_interface'

network = models.ForeignKey('Network')
Expand Down Expand Up @@ -284,7 +284,7 @@ def _create(mac_addr=None):


class Address(models.Model):
class Meta:
class Meta(object):
db_table = 'devops_address'

interface = models.ForeignKey('Interface')
Expand Down
2 changes: 1 addition & 1 deletion devops/models/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def all(self, *args, **kwargs):


class Node(DriverModel):
class Meta:
class Meta(object):
unique_together = ('name', 'environment')
db_table = 'devops_node'

Expand Down
2 changes: 1 addition & 1 deletion devops/models/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


class Volume(DriverModel):
class Meta:
class Meta(object):
unique_together = ('name', 'environment')
db_table = 'devops_volume'

Expand Down
2 changes: 1 addition & 1 deletion devops/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def do_slave_add(self, force_define=True):
node_count = self.params.node_count

for node in xrange(created_nodes, created_nodes + node_count):
node_name = "slave-%02d" % (node)
node_name = "slave-{node:02d}".format(node=node)
node = self.env.add_node(name=node_name, vcpu=vcpu, memory=memory)
disknames_capacity = {
'system': 50 * 1024 ** 3
Expand Down
4 changes: 2 additions & 2 deletions devops/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ def fuzz(self):

@factory.use_strategy(factory.BUILD_STRATEGY)
class EnvironmentFactory(factory.django.DjangoModelFactory):
class Meta:
class Meta(object):
model = models.Environment

name = fuzzy.FuzzyText('test_env_')


@factory.use_strategy(factory.BUILD_STRATEGY)
class VolumeFactory(factory.django.DjangoModelFactory):
class Meta:
class Meta(object):
model = models.Volume

environment = factory.SubFactory(EnvironmentFactory)
Expand Down
15 changes: 7 additions & 8 deletions devops/tests/test_libvirt_xml_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ def setUp(self):
self.xml_builder.driver.use_hugepages = None

def _reformat_xml(self, xml):
"""Takes XML in string, parses it and returns pretty printted XML."""
"""Takes XML in string, parses it and returns pretty printed XML."""
return etree.tostring(etree.fromstring(xml), pretty_print=True)

def assertXMLEqual(self, first, second):
"""Compare if two XMLs are equal.
It parses provided XMLs and converts back to string to minimalise
It parses provided XMLs and converts back to string to minimise
errors caused by whitespaces.
"""
first = self._reformat_xml(first)
Expand Down Expand Up @@ -128,9 +128,8 @@ def test_ip_network(self):
self.net.has_pxe_server = False
self.net.tftp_root_dir = '/tmp'
xml = self.xml_builder.build_network_xml(self.net)
str = '<ip address="{0}" prefix="{1}" />'.format(
ip, prefix)
self.assertXMLIn(str, xml)
string = '<ip address="{0}" prefix="{1}" />'.format(ip, prefix)
self.assertXMLIn(string, xml)


class TestVolumeXml(BaseTestXMLBuilder):
Expand Down Expand Up @@ -179,14 +178,14 @@ def test_no_backing_store(self):
self.assertXpath("not(//backingStore)", xml)

def test_backing_store(self):
format = "raw"
volume = factories.VolumeFactory(backing_store__format=format)
store_format = "raw"
volume = factories.VolumeFactory(backing_store__format=store_format)
xml = self.get_xml(volume)
self.assertXMLIn('''
<backingStore>
<path>{path}</path>
<format type="{format}" />
</backingStore>'''.format(path=self.volume_path, format=format), xml)
</backingStore>'''.format(path=self.volume_path, format=store_format), xml)


class TestSnapshotXml(BaseTestXMLBuilder):
Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# -- General configuration ----------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions
Expand All @@ -50,7 +50,7 @@
source_suffix = '.rst'

# The encoding of source files.
#source_encoding = 'utf-8-sig'
# source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'
Expand Down
2 changes: 1 addition & 1 deletion docs/source/getstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Now it is time to configure it. You can edit default configuration file devops/s

Once database parameters configured it is needed to install corresponding database and configure database itself to make devops applications possible to access to it. For example, to configure Postgresql you need to edit pg_hba.conf file and create configured user and database.

All virtual machines names and virtual networks names will be prepended with environment name avoiding name clashes. As long as different devops applications use not overlaped network ranges and evironments names it is possible to use differnt database for every application. If you are not absolutely sure just use the same database configuration for all devops instances. Once database and devops configured you need to create database schema.
All virtual machines names and virtual networks names will be prepended with environment name avoiding name clashes. As long as different devops applications use not overlapped network ranges and environments names it is possible to use different database for every application. If you are not absolutely sure just use the same database configuration for all devops instances. Once database and devops configured you need to create database schema.

::

Expand Down

0 comments on commit cc2ed26

Please sign in to comment.