Commit 3582eef6 authored by Iustin Pop's avatar Iustin Pop
Browse files

Run pylint over QA code too



Right now, the QA code is not covered by pylint, and this shows at
least one low-impact bug.

This patch does the necessary changes to make QA pylint-clean, and the
changes the makefile to run pylint for it.

Notable changes:

- qa_utils.GenericQueryTest: randfields was not used at all, and my
  belief is that it was indented to be used in order not to modify the
  input list; so I replaced randfields with fields, so we only shuffle
  the our local copy
- qa_node.TestOutOfBand was using it's own copy of AcquireNode(), so I
  replaced it with the existing version
- qa_os: was using 'dir' in a couple of places, replaced with dirname
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent f7e6f3c8
...@@ -802,6 +802,9 @@ check-local: check-dirs ...@@ -802,6 +802,9 @@ check-local: check-dirs
lint: $(BUILT_SOURCES) lint: $(BUILT_SOURCES)
@test -n "$(PYLINT)" || { echo 'pylint' not found during configure; exit 1; } @test -n "$(PYLINT)" || { echo 'pylint' not found during configure; exit 1; }
$(PYLINT) $(LINT_OPTS) $(lint_python_code) $(PYLINT) $(LINT_OPTS) $(lint_python_code)
cd $(top_srcdir)/qa && \
PYTHONPATH=$(abs_top_srcdir) $(PYLINT) $(LINT_OPTS) \
--rcfile ../pylintrc $(patsubst qa/%.py,%,$(qa_scripts))
# a dist hook rule for updating the vcs-version file; this is # a dist hook rule for updating the vcs-version file; this is
# hardcoded due to where it needs to build the file... # hardcoded due to where it needs to build the file...
......
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
""" """
# pylint: disable-msg=C0103
# due to invalid name
import sys import sys
import datetime import datetime
import optparse import optparse
...@@ -43,7 +46,7 @@ from ganeti import utils ...@@ -43,7 +46,7 @@ from ganeti import utils
from ganeti import rapi from ganeti import rapi
from ganeti import constants from ganeti import constants
import ganeti.rapi.client import ganeti.rapi.client # pylint: disable-msg=W0611
def _FormatHeader(line, end=72): def _FormatHeader(line, end=72):
......
# #
# #
# Copyright (C) 2007 Google Inc. # Copyright (C) 2007, 2011 Google Inc.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
...@@ -39,7 +39,7 @@ def Load(path): ...@@ -39,7 +39,7 @@ def Load(path):
"""Loads the passed configuration file. """Loads the passed configuration file.
""" """
global cfg global cfg # pylint: disable-msg=W0603
cfg = serializer.LoadJson(utils.ReadFile(path)) cfg = serializer.LoadJson(utils.ReadFile(path))
......
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
# 02110-1301, USA. # 02110-1301, USA.
"""Error definitions for QA.
"""
class Error(Exception): class Error(Exception):
"""An error occurred during Q&A testing. """An error occurred during Q&A testing.
......
# #
# #
# Copyright (C) 2010 Google Inc. # Copyright (C) 2010, 2011 Google Inc.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
# 02110-1301, USA. # 02110-1301, USA.
"""QA tests for node groups.
"""
from ganeti import constants from ganeti import constants
from ganeti import query from ganeti import query
from ganeti import utils from ganeti import utils
......
# #
# #
# Copyright (C) 2007 Google Inc. # Copyright (C) 2007, 2011 Google Inc.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
...@@ -225,6 +225,9 @@ def TestInstanceConsole(instance): ...@@ -225,6 +225,9 @@ def TestInstanceConsole(instance):
def TestReplaceDisks(instance, pnode, snode, othernode): def TestReplaceDisks(instance, pnode, snode, othernode):
"""gnt-instance replace-disks""" """gnt-instance replace-disks"""
# pylint: disable-msg=W0613
# due to unused pnode arg
# FIXME: should be removed from the function completely
def buildcmd(args): def buildcmd(args):
cmd = ['gnt-instance', 'replace-disks'] cmd = ['gnt-instance', 'replace-disks']
cmd.extend(args) cmd.extend(args)
...@@ -393,6 +396,8 @@ def _TestInstanceDiskFailure(instance, node, node2, onmaster): ...@@ -393,6 +396,8 @@ def _TestInstanceDiskFailure(instance, node, node2, onmaster):
def TestInstanceMasterDiskFailure(instance, node, node2): def TestInstanceMasterDiskFailure(instance, node, node2):
"""Testing disk failure on master node.""" """Testing disk failure on master node."""
# pylint: disable-msg=W0613
# due to unused args
print qa_utils.FormatError("Disk failure on primary node cannot be" print qa_utils.FormatError("Disk failure on primary node cannot be"
" tested due to potential crashes.") " tested due to potential crashes.")
# The following can cause crashes, thus it's disabled until fixed # The following can cause crashes, thus it's disabled until fixed
......
# #
# #
# Copyright (C) 2007 Google Inc. # Copyright (C) 2007, 2011 Google Inc.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
# 02110-1301, USA. # 02110-1301, USA.
"""Node-related QA tests.
"""
from ganeti import utils from ganeti import utils
from ganeti import constants from ganeti import constants
from ganeti import query from ganeti import query
...@@ -232,12 +236,7 @@ def TestOutOfBand(): ...@@ -232,12 +236,7 @@ def TestOutOfBand():
"""gnt-node power""" """gnt-node power"""
master = qa_config.GetMasterNode() master = qa_config.GetMasterNode()
# Find first non master node for tests node = qa_config.AcquireNode(exclude=master)
for node in qa_config.get("nodes"):
if node != master:
break
else:
raise qa_error.Error("Can't find non-master node")
node_name = node["primary"] node_name = node["primary"]
full_node_name = qa_utils.ResolveNodeName(node) full_node_name = qa_utils.ResolveNodeName(node)
......
# #
# #
# Copyright (C) 2007, 2008, 2009, 2010 Google Inc. # Copyright (C) 2007, 2008, 2009, 2010, 2011 Google Inc.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
...@@ -76,14 +76,14 @@ def _TestOsStates(): ...@@ -76,14 +76,14 @@ def _TestOsStates():
AssertCommand(new_cmd) AssertCommand(new_cmd)
def _SetupTempOs(node, dir, valid): def _SetupTempOs(node, dirname, valid):
"""Creates a temporary OS definition on the given node. """Creates a temporary OS definition on the given node.
""" """
sq = utils.ShellQuoteArgs sq = utils.ShellQuoteArgs
parts = [sq(["rm", "-rf", dir]), parts = [sq(["rm", "-rf", dirname]),
sq(["mkdir", "-p", dir]), sq(["mkdir", "-p", dirname]),
sq(["cd", dir]), sq(["cd", dirname]),
sq(["ln", "-fs", "/bin/true", "export"]), sq(["ln", "-fs", "/bin/true", "export"]),
sq(["ln", "-fs", "/bin/true", "import"]), sq(["ln", "-fs", "/bin/true", "import"]),
sq(["ln", "-fs", "/bin/true", "rename"])] sq(["ln", "-fs", "/bin/true", "rename"])]
...@@ -103,18 +103,18 @@ def _SetupTempOs(node, dir, valid): ...@@ -103,18 +103,18 @@ def _SetupTempOs(node, dir, valid):
AssertCommand(cmd, node=node) AssertCommand(cmd, node=node)
def _RemoveTempOs(node, dir): def _RemoveTempOs(node, dirname):
"""Removes a temporary OS definition. """Removes a temporary OS definition.
""" """
AssertCommand(["rm", "-rf", dir], node=node) AssertCommand(["rm", "-rf", dirname], node=node)
def _TestOs(mode): def _TestOs(mode):
"""Generic function for OS definition testing """Generic function for OS definition testing
""" """
dir = _TEMP_OS_PATH dirname = _TEMP_OS_PATH
nodes = [] nodes = []
try: try:
...@@ -126,12 +126,12 @@ def _TestOs(mode): ...@@ -126,12 +126,12 @@ def _TestOs(mode):
valid = True valid = True
else: else:
valid = bool(i % 2) valid = bool(i % 2)
_SetupTempOs(node, dir, valid) _SetupTempOs(node, dirname, valid)
AssertCommand(["gnt-os", "diagnose"], fail=not mode==1) AssertCommand(["gnt-os", "diagnose"], fail=not mode==1)
finally: finally:
for node in nodes: for node in nodes:
_RemoveTempOs(node, dir) _RemoveTempOs(node, dirname)
def TestOsValid(): def TestOsValid():
......
# #
# Copyright (C) 2007, 2008, 2009, 2010 Google Inc. # Copyright (C) 2007, 2008, 2009, 2010, 2011 Google Inc.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
...@@ -27,19 +27,17 @@ import tempfile ...@@ -27,19 +27,17 @@ import tempfile
from ganeti import utils from ganeti import utils
from ganeti import constants from ganeti import constants
from ganeti import errors from ganeti import errors
from ganeti import serializer
from ganeti import cli from ganeti import cli
from ganeti import rapi from ganeti import rapi
import ganeti.rapi.client import ganeti.rapi.client # pylint: disable-msg=W0611
import ganeti.rapi.client_utils import ganeti.rapi.client_utils
import qa_config import qa_config
import qa_utils import qa_utils
import qa_error import qa_error
from qa_utils import (AssertEqual, AssertNotEqual, AssertIn, AssertMatch, from qa_utils import (AssertEqual, AssertIn, AssertMatch, StartLocalCommand)
StartLocalCommand)
_rapi_ca = None _rapi_ca = None
...@@ -52,6 +50,8 @@ def Setup(username, password): ...@@ -52,6 +50,8 @@ def Setup(username, password):
"""Configures the RAPI client. """Configures the RAPI client.
""" """
# pylint: disable-msg=W0603
# due to global usage
global _rapi_ca global _rapi_ca
global _rapi_client global _rapi_client
global _rapi_username global _rapi_username
...@@ -117,6 +117,8 @@ def Enabled(): ...@@ -117,6 +117,8 @@ def Enabled():
def _DoTests(uris): def _DoTests(uris):
# pylint: disable-msg=W0212
# due to _SendRequest usage
results = [] results = []
for uri, verify, method, body in uris: for uri, verify, method, body in uris:
...@@ -322,8 +324,6 @@ def _WaitForRapiJob(job_id): ...@@ -322,8 +324,6 @@ def _WaitForRapiJob(job_id):
"""Waits for a job to finish. """Waits for a job to finish.
""" """
master = qa_config.GetMasterNode()
def _VerifyJob(data): def _VerifyJob(data):
AssertEqual(data["id"], job_id) AssertEqual(data["id"], job_id)
for field in JOB_FIELDS: for field in JOB_FIELDS:
......
...@@ -50,6 +50,8 @@ def _SetupColours(): ...@@ -50,6 +50,8 @@ def _SetupColours():
"""Initializes the colour constants. """Initializes the colour constants.
""" """
# pylint: disable-msg=W0603
# due to global usage
global _INFO_SEQ, _WARNING_SEQ, _ERROR_SEQ, _RESET_SEQ global _INFO_SEQ, _WARNING_SEQ, _ERROR_SEQ, _RESET_SEQ
# Don't use colours if stdout isn't a terminal # Don't use colours if stdout isn't a terminal
...@@ -403,7 +405,7 @@ def GenericQueryTest(cmd, fields): ...@@ -403,7 +405,7 @@ def GenericQueryTest(cmd, fields):
""" """
rnd = random.Random(hash(cmd)) rnd = random.Random(hash(cmd))
randfields = list(fields) fields = list(fields)
rnd.shuffle(fields) rnd.shuffle(fields)
# Test a number of field combinations # Test a number of field combinations
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment