From 85940d58f2bf7cb7aae68c01215d4ebc97925337 Mon Sep 17 00:00:00 2001 From: David Fairbrother Date: Thu, 26 Oct 2023 10:15:58 +0100 Subject: [PATCH 1/3] Update pylintrc file Update the pylintrc file to reflect the latest version generated from pylint on Python 3.10.x --- OpenStack-Rabbit-Consumer/.pylintrc | 40 ++++++++++++++--------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/OpenStack-Rabbit-Consumer/.pylintrc b/OpenStack-Rabbit-Consumer/.pylintrc index 18ec8e46..d4cfd47a 100644 --- a/OpenStack-Rabbit-Consumer/.pylintrc +++ b/OpenStack-Rabbit-Consumer/.pylintrc @@ -5,6 +5,10 @@ # only in one or another interpreter, leading to false positives when analysed. analyse-fallback-blocks=no +# Clear in-memory caches upon conclusion of linting. Useful if running pylint +# in a server-like mode. +clear-cache-post-run=no + # Load and enable all available extensions. Use --list-extensions to see a list # all available extensions. #enable-all-extensions= @@ -63,7 +67,7 @@ ignored-modules= # Python code to execute, usually for sys.path manipulation such as # pygtk.require(). -init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))" +#init-hook= # Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the # number of processors available to use, and will cap the count on Windows to @@ -248,22 +252,15 @@ check-protected-access-in-special-methods=no defining-attr-methods=__init__, __new__, setUp, + asyncSetUp, __post_init__ # List of member names, which should be excluded from the protected access # warning. -exclude-protected=_asdict, - _fields, - _replace, - _source, - _make +exclude-protected=_asdict,_fields,_replace,_source,_make,os._exit # List of valid names for the first argument in a class method. -valid-classmethod-first-arg=cls - -# List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg=cls - +valid-metaclass-classmethod-first-arg=mcs [DESIGN] @@ -309,9 +306,7 @@ min-public-methods=2 [EXCEPTIONS] # Exceptions that will emit a warning when caught. -overgeneral-exceptions=builtins.BaseException, - builtins.Exception - +overgeneral-exceptions=builtins.BaseException,builtins.Exception [FORMAT] @@ -410,10 +405,15 @@ confidence=HIGH, # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use "--disable=all --enable=classes # --disable=W". -disable=line-too-long, - missing-module-docstring, - missing-function-docstring, - fixme +disable=raw-checker-failed, + bad-inline-option, + locally-disabled, + file-ignored, + suppressed-message, + useless-suppression, + deprecated-pragma, + use-symbolic-message-instead, + line-too-long # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option @@ -500,8 +500,8 @@ min-similarity-lines=4 # Limits count of emitted suggestions for spelling mistakes. max-spelling-suggestions=4 -# Spelling dictionary name. Available dictionaries: none. To make it work, -# install the 'python-enchant' package. +# Spelling dictionary name. No available dictionaries : You need to install +# both the python package and the system dependency for enchant to work.. spelling-dict= # List of comma separated words that should be considered directives if they From 1cf4ab9c602f1572ff2b50a077ab6247595945e2 Mon Sep 17 00:00:00 2001 From: meoflynn Date: Thu, 26 Oct 2023 11:26:56 +0100 Subject: [PATCH 2/3] DOC: Add missing module docstrings Added module docstrings that were missing for the rabbit consumers --- OpenStack-Rabbit-Consumer/rabbit_consumer/aq_api.py | 4 ++++ OpenStack-Rabbit-Consumer/rabbit_consumer/aq_metadata.py | 4 ++++ OpenStack-Rabbit-Consumer/rabbit_consumer/consumer_config.py | 5 +++++ .../rabbit_consumer/message_consumer.py | 4 ++++ .../rabbit_consumer/openstack_address.py | 4 ++++ OpenStack-Rabbit-Consumer/rabbit_consumer/openstack_api.py | 4 ++++ OpenStack-Rabbit-Consumer/rabbit_consumer/rabbit_message.py | 4 ++++ OpenStack-Rabbit-Consumer/rabbit_consumer/vm_data.py | 3 +++ 8 files changed, 32 insertions(+) diff --git a/OpenStack-Rabbit-Consumer/rabbit_consumer/aq_api.py b/OpenStack-Rabbit-Consumer/rabbit_consumer/aq_api.py index 77369201..b47bf975 100644 --- a/OpenStack-Rabbit-Consumer/rabbit_consumer/aq_api.py +++ b/OpenStack-Rabbit-Consumer/rabbit_consumer/aq_api.py @@ -1,3 +1,7 @@ +""" +This file defines methods to be used to interact with the +Aquilon API +""" import logging import subprocess from typing import Optional, List diff --git a/OpenStack-Rabbit-Consumer/rabbit_consumer/aq_metadata.py b/OpenStack-Rabbit-Consumer/rabbit_consumer/aq_metadata.py index 34ebb90e..b9997abd 100644 --- a/OpenStack-Rabbit-Consumer/rabbit_consumer/aq_metadata.py +++ b/OpenStack-Rabbit-Consumer/rabbit_consumer/aq_metadata.py @@ -1,3 +1,7 @@ +""" +This file defines the class to handle deserialised metadata for +Aquilon +""" import logging from dataclasses import dataclass from typing import Dict, Optional diff --git a/OpenStack-Rabbit-Consumer/rabbit_consumer/consumer_config.py b/OpenStack-Rabbit-Consumer/rabbit_consumer/consumer_config.py index caead1b9..27c8e815 100644 --- a/OpenStack-Rabbit-Consumer/rabbit_consumer/consumer_config.py +++ b/OpenStack-Rabbit-Consumer/rabbit_consumer/consumer_config.py @@ -1,3 +1,8 @@ +""" +This file allows us to set environment variables so that +credentials are not exposed +""" + import os from dataclasses import dataclass, field from functools import partial diff --git a/OpenStack-Rabbit-Consumer/rabbit_consumer/message_consumer.py b/OpenStack-Rabbit-Consumer/rabbit_consumer/message_consumer.py index 9acc2fdb..cc4a55f6 100644 --- a/OpenStack-Rabbit-Consumer/rabbit_consumer/message_consumer.py +++ b/OpenStack-Rabbit-Consumer/rabbit_consumer/message_consumer.py @@ -1,3 +1,7 @@ +""" +This file manages how rabbit messages stating AQ VM creation and deletion +should be handled and processed between the consumer and Aquilon +""" import json import logging import socket diff --git a/OpenStack-Rabbit-Consumer/rabbit_consumer/openstack_address.py b/OpenStack-Rabbit-Consumer/rabbit_consumer/openstack_address.py index eaaf7fb1..fcd2a520 100644 --- a/OpenStack-Rabbit-Consumer/rabbit_consumer/openstack_address.py +++ b/OpenStack-Rabbit-Consumer/rabbit_consumer/openstack_address.py @@ -1,3 +1,7 @@ +""" +This file deserializes a server's network address from an +OpenStack API response +""" import logging import socket from dataclasses import dataclass, field diff --git a/OpenStack-Rabbit-Consumer/rabbit_consumer/openstack_api.py b/OpenStack-Rabbit-Consumer/rabbit_consumer/openstack_api.py index f582a5f7..436e1cd1 100644 --- a/OpenStack-Rabbit-Consumer/rabbit_consumer/openstack_api.py +++ b/OpenStack-Rabbit-Consumer/rabbit_consumer/openstack_api.py @@ -1,3 +1,7 @@ +""" +This file defines methods for connecting and interacting with the +OpenStack API +""" import logging from typing import List, Optional diff --git a/OpenStack-Rabbit-Consumer/rabbit_consumer/rabbit_message.py b/OpenStack-Rabbit-Consumer/rabbit_consumer/rabbit_message.py index 3ee38a4c..0d2fac13 100644 --- a/OpenStack-Rabbit-Consumer/rabbit_consumer/rabbit_message.py +++ b/OpenStack-Rabbit-Consumer/rabbit_consumer/rabbit_message.py @@ -1,3 +1,7 @@ +""" +This file handles how messages from Rabbit are processed and the +message extracted +""" from dataclasses import dataclass, field from typing import Optional diff --git a/OpenStack-Rabbit-Consumer/rabbit_consumer/vm_data.py b/OpenStack-Rabbit-Consumer/rabbit_consumer/vm_data.py index e3e2ea60..89c70c89 100644 --- a/OpenStack-Rabbit-Consumer/rabbit_consumer/vm_data.py +++ b/OpenStack-Rabbit-Consumer/rabbit_consumer/vm_data.py @@ -1,3 +1,6 @@ +""" +This file has a dataclass for creating VM data objects from messages +""" from dataclasses import dataclass from rabbit_consumer.rabbit_message import RabbitMessage From a05091755291f55c839ccaea52e5f4dddaedcad9 Mon Sep 17 00:00:00 2001 From: David Fairbrother Date: Mon, 30 Oct 2023 11:55:45 +0000 Subject: [PATCH 3/3] Add missing doc strings to module Adds additional missing doc strings, and fixes various pylint warnings since updating the rc file --- OpenStack-Rabbit-Consumer/test/fixtures.py | 3 +++ OpenStack-Rabbit-Consumer/test/test_aq_api.py | 4 ++++ OpenStack-Rabbit-Consumer/test/test_aq_metadata.py | 5 +++++ OpenStack-Rabbit-Consumer/test/test_consumer_config.py | 4 ++++ OpenStack-Rabbit-Consumer/test/test_message_consumer.py | 7 +++++++ OpenStack-Rabbit-Consumer/test/test_openstack_address.py | 3 +++ OpenStack-Rabbit-Consumer/test/test_openstack_api.py | 9 +++++++++ OpenStack-Rabbit-Consumer/test/test_rabbit_message.py | 3 +++ 8 files changed, 38 insertions(+) diff --git a/OpenStack-Rabbit-Consumer/test/fixtures.py b/OpenStack-Rabbit-Consumer/test/fixtures.py index 39409831..61cfd501 100644 --- a/OpenStack-Rabbit-Consumer/test/fixtures.py +++ b/OpenStack-Rabbit-Consumer/test/fixtures.py @@ -1,3 +1,6 @@ +""" +Fixtures for unit tests, used to create mock objects +""" import uuid import pytest diff --git a/OpenStack-Rabbit-Consumer/test/test_aq_api.py b/OpenStack-Rabbit-Consumer/test/test_aq_api.py index 8fd43556..ca52af47 100644 --- a/OpenStack-Rabbit-Consumer/test/test_aq_api.py +++ b/OpenStack-Rabbit-Consumer/test/test_aq_api.py @@ -1,3 +1,7 @@ +""" +Tests that we perform the correct REST requests against +the Aquilon API +""" from unittest import mock from unittest.mock import patch, call, NonCallableMock diff --git a/OpenStack-Rabbit-Consumer/test/test_aq_metadata.py b/OpenStack-Rabbit-Consumer/test/test_aq_metadata.py index 8ad68d1b..6d65b441 100644 --- a/OpenStack-Rabbit-Consumer/test/test_aq_metadata.py +++ b/OpenStack-Rabbit-Consumer/test/test_aq_metadata.py @@ -1,3 +1,8 @@ +""" +Tests the AQ metadata dataclass, including +init from environment variables, and overriding values +""" + from typing import Dict import pytest diff --git a/OpenStack-Rabbit-Consumer/test/test_consumer_config.py b/OpenStack-Rabbit-Consumer/test/test_consumer_config.py index bb14d5d9..8c62646a 100644 --- a/OpenStack-Rabbit-Consumer/test/test_consumer_config.py +++ b/OpenStack-Rabbit-Consumer/test/test_consumer_config.py @@ -1,3 +1,7 @@ +""" +Test the consumer config class, this handles the environment variables +that are used to configure the consumer. +""" import pytest from rabbit_consumer.consumer_config import ConsumerConfig diff --git a/OpenStack-Rabbit-Consumer/test/test_message_consumer.py b/OpenStack-Rabbit-Consumer/test/test_message_consumer.py index 409284ee..a4310102 100644 --- a/OpenStack-Rabbit-Consumer/test/test_message_consumer.py +++ b/OpenStack-Rabbit-Consumer/test/test_message_consumer.py @@ -1,3 +1,7 @@ +""" +Tests the message consumption flow +for the consumer +""" from unittest.mock import Mock, NonCallableMock, patch, call, MagicMock import pytest @@ -413,6 +417,9 @@ def test_delete_machine_by_serial(aq_api, vm_data, openstack_address): @patch("rabbit_consumer.message_consumer.aq_api") @patch("rabbit_consumer.message_consumer.socket") def test_delete_machine_no_hostname(socket_api, aq_api, vm_data): + """ + Tests + """ aq_api.check_host_exists.return_value = False ip_address = "127.0.0.1" diff --git a/OpenStack-Rabbit-Consumer/test/test_openstack_address.py b/OpenStack-Rabbit-Consumer/test/test_openstack_address.py index 4a049964..2d011ca4 100644 --- a/OpenStack-Rabbit-Consumer/test/test_openstack_address.py +++ b/OpenStack-Rabbit-Consumer/test/test_openstack_address.py @@ -1,3 +1,6 @@ +""" +Tests the dataclass representing OpenStack network addresses +""" import copy from unittest.mock import patch diff --git a/OpenStack-Rabbit-Consumer/test/test_openstack_api.py b/OpenStack-Rabbit-Consumer/test/test_openstack_api.py index a6274f08..02b347e1 100644 --- a/OpenStack-Rabbit-Consumer/test/test_openstack_api.py +++ b/OpenStack-Rabbit-Consumer/test/test_openstack_api.py @@ -1,3 +1,7 @@ +""" +Tests that the Openstack API functions are invoked +as expected with the correct params +""" from unittest.mock import NonCallableMock, patch # noinspection PyUnresolvedReferences @@ -29,9 +33,14 @@ def test_openstack_connection(mock_connect, mock_config): project_domain_name="default", ) + # Pylint is unable to see that openstack.connect returns a mock + # pylint: disable=no-member assert conn == mock_connect.return_value + # pylint: disable=no-member assert conn.close.call_count == 0 + # Check close is called when the context manager exits + # pylint: disable=no-member assert conn.close.call_count == 1 diff --git a/OpenStack-Rabbit-Consumer/test/test_rabbit_message.py b/OpenStack-Rabbit-Consumer/test/test_rabbit_message.py index baa04c9e..16fa326d 100644 --- a/OpenStack-Rabbit-Consumer/test/test_rabbit_message.py +++ b/OpenStack-Rabbit-Consumer/test/test_rabbit_message.py @@ -1,3 +1,6 @@ +""" +Tests rabbit messages are consumed correctly from the queue +""" import json from typing import Dict