From 2057dcd64aa1735d749ed58482420193bd33671f Mon Sep 17 00:00:00 2001 From: Carlos Nihelton Date: Thu, 2 Mar 2023 09:09:39 -0300 Subject: [PATCH] Consistent naming - part 1 - AdModel No other class starts with both capitals 'AD'. --- scripts/test-ad-setup.py | 4 ++-- subiquity/common/apidef.py | 6 +++--- subiquity/common/types.py | 2 +- subiquity/models/ad.py | 10 +++++----- subiquity/models/subiquity.py | 4 ++-- subiquity/server/ad_joiner.py | 8 ++++---- subiquity/server/controllers/__init__.py | 4 ++-- subiquity/server/controllers/ad.py | 10 +++++----- subiquity/server/controllers/install.py | 2 +- subiquity/server/controllers/tests/test_ad.py | 20 +++++++++---------- subiquity/server/server.py | 2 +- 11 files changed, 36 insertions(+), 36 deletions(-) diff --git a/scripts/test-ad-setup.py b/scripts/test-ad-setup.py index 5249462a..237e867f 100755 --- a/scripts/test-ad-setup.py +++ b/scripts/test-ad-setup.py @@ -8,7 +8,7 @@ import logging import re import os from typing import List -from subiquity.models.ad import ADModel +from subiquity.models.ad import AdModel class FailedTestCase(Exception): @@ -18,7 +18,7 @@ class FailedTestCase(Exception): async def target_packages() -> List[str]: """ Returns the list of packages the AD Model wants to install in the target system.""" - model = ADModel() + model = AdModel() model.do_join = True return await model.target_packages() diff --git a/subiquity/common/apidef.py b/subiquity/common/apidef.py index f0f0d0ab..be50bbf9 100644 --- a/subiquity/common/apidef.py +++ b/subiquity/common/apidef.py @@ -25,7 +25,7 @@ from subiquitycore.models.network import ( from subiquity.common.api.defs import api, Payload, simple_endpoint from subiquity.common.types import ( - ADConnectionInfo, + AdConnectionInfo, AdAdminNameValidation, AdDomainNameValidation, AdJoinResult, @@ -415,9 +415,9 @@ class API: def GET() -> CasperMd5Results: ... class active_directory: - def GET() -> Optional[ADConnectionInfo]: ... + def GET() -> Optional[AdConnectionInfo]: ... # POST expects input validated by the check methods below: - def POST(data: Payload[ADConnectionInfo]) -> None: ... + def POST(data: Payload[AdConnectionInfo]) -> None: ... class has_support: """ Whether the live system supports Active Directory or not. diff --git a/subiquity/common/types.py b/subiquity/common/types.py index 4875f97b..2bffefa2 100644 --- a/subiquity/common/types.py +++ b/subiquity/common/types.py @@ -773,7 +773,7 @@ class MirrorSelectionFallback(enum.Enum): @attr.s(auto_attribs=True) -class ADConnectionInfo: +class AdConnectionInfo: admin_name: str = "" domain_name: str = "" password: str = attr.ib(repr=False, default="") diff --git a/subiquity/models/ad.py b/subiquity/models/ad.py index 1816b8a4..d9c626cc 100644 --- a/subiquity/models/ad.py +++ b/subiquity/models/ad.py @@ -16,18 +16,18 @@ import logging from typing import Optional -from subiquity.common.types import ADConnectionInfo +from subiquity.common.types import AdConnectionInfo log = logging.getLogger('subiquity.models.ad') -class ADModel: +class AdModel: """ Models the Active Directory feature """ def __init__(self) -> None: self.do_join = False - self.conn_info: Optional[ADConnectionInfo] = None + self.conn_info: Optional[AdConnectionInfo] = None - def set(self, info: ADConnectionInfo): + def set(self, info: AdConnectionInfo): self.conn_info = info self.do_join = True @@ -39,7 +39,7 @@ class ADModel: self.conn_info.domain_name = domain else: - self.conn_info = ADConnectionInfo(domain_name=domain) + self.conn_info = AdConnectionInfo(domain_name=domain) async def target_packages(self): # NOTE Those packages must be present in the target system to allow diff --git a/subiquity/models/subiquity.py b/subiquity/models/subiquity.py index 87d159cc..fd00a45c 100644 --- a/subiquity/models/subiquity.py +++ b/subiquity/models/subiquity.py @@ -46,7 +46,7 @@ from subiquitycore.lsb_release import lsb_release from subiquity.common.resources import get_users_and_groups from subiquity.server.types import InstallerChannels -from .ad import ADModel +from .ad import AdModel from .codecs import CodecsModel from .drivers import DriversModel from .filesystem import FilesystemModel @@ -180,7 +180,7 @@ class SubiquityModel: self.target = root self.chroot_prefix = [] - self.ad = ADModel() + self.ad = AdModel() self.codecs = CodecsModel() self.debconf_selections = DebconfSelectionsModel() self.drivers = DriversModel() diff --git a/subiquity/server/ad_joiner.py b/subiquity/server/ad_joiner.py index 22ad2ac7..872a0d2a 100644 --- a/subiquity/server/ad_joiner.py +++ b/subiquity/server/ad_joiner.py @@ -21,7 +21,7 @@ from subprocess import CalledProcessError from subiquitycore.utils import arun_command, run_command from subiquity.server.curtin import run_curtin_command from subiquity.common.types import ( - ADConnectionInfo, + AdConnectionInfo, AdJoinResult, ) @@ -50,7 +50,7 @@ class AdJoinStrategy(): def __init__(self, app): self.app = app - async def do_join(self, info: ADConnectionInfo, hostname: str, context) \ + async def do_join(self, info: AdConnectionInfo, hostname: str, context) \ -> AdJoinResult: """ This method changes the hostname and perform a real AD join, thus should only run in a live session. """ @@ -109,7 +109,7 @@ class AdJoinStrategy(): class StubStrategy(AdJoinStrategy): - async def do_join(self, info: ADConnectionInfo, hostname: str, context) \ + async def do_join(self, info: AdConnectionInfo, hostname: str, context) \ -> AdJoinResult: """ Enables testing without real join. The result depends on the domain name initial character, such that if it is: @@ -135,7 +135,7 @@ class AdJoiner(): else: self.strategy = AdJoinStrategy(app) - async def join_domain(self, info: ADConnectionInfo, hostname: str, + async def join_domain(self, info: AdConnectionInfo, hostname: str, context) -> AdJoinResult: if hostname: self._result = await self.strategy.do_join(info, hostname, context) diff --git a/subiquity/server/controllers/__init__.py b/subiquity/server/controllers/__init__.py index 7353ad3d..46fd4029 100644 --- a/subiquity/server/controllers/__init__.py +++ b/subiquity/server/controllers/__init__.py @@ -13,7 +13,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from .ad import ADController +from .ad import AdController from .cmdlist import EarlyController, LateController, ErrorController from .codecs import CodecsController from .debconf import DebconfController @@ -42,7 +42,7 @@ from .userdata import UserdataController from .zdev import ZdevController __all__ = [ - 'ADController', + 'AdController', 'CodecsController', 'DebconfController', 'DriversController', diff --git a/subiquity/server/controllers/ad.py b/subiquity/server/controllers/ad.py index 13eb7fbb..b0662522 100644 --- a/subiquity/server/controllers/ad.py +++ b/subiquity/server/controllers/ad.py @@ -22,7 +22,7 @@ from subiquitycore.async_helpers import run_bg_task from subiquity.common.apidef import API from subiquity.common.types import ( - ADConnectionInfo, + AdConnectionInfo, AdAdminNameValidation, AdDomainNameValidation, AdJoinResult, @@ -89,7 +89,7 @@ class StubDcPingStrategy(DcPingStrategy): return True -class ADController(SubiquityController): +class AdController(SubiquityController): """ Implements the server part of the Active Directory feature. """ endpoint = API.active_directory # No auto install key and schema for now due password handling uncertainty. @@ -119,7 +119,7 @@ class ADController(SubiquityController): if state is None: return if 'admin_name' in state and 'domain_name' in state: - info = ADConnectionInfo(admin_name=state['admin_name'], + info = AdConnectionInfo(admin_name=state['admin_name'], domain_name=state['domain_name']) self.model.set(info) @@ -153,11 +153,11 @@ class ADController(SubiquityController): if discovered_domain: self.model.set_domain(discovered_domain) - async def GET(self) -> Optional[ADConnectionInfo]: + async def GET(self) -> Optional[AdConnectionInfo]: """Returns the currently configured AD settings""" return self.model.conn_info - async def POST(self, data: ADConnectionInfo) -> None: + async def POST(self, data: AdConnectionInfo) -> None: """ Configures this controller with the supplied info. Clients are required to validate the info before POST'ing """ self.model.set(data) diff --git a/subiquity/server/controllers/install.py b/subiquity/server/controllers/install.py index bc37ca0a..039f6380 100644 --- a/subiquity/server/controllers/install.py +++ b/subiquity/server/controllers/install.py @@ -412,7 +412,7 @@ class InstallController(SubiquityController): with open(self.tpath('etc/hostname'), 'r') as f: hostname = f.read().strip() - await self.app.controllers.AD.join_domain(hostname, context) + await self.app.controllers.Ad.join_domain(hostname, context) @with_context(description="configuring cloud-init") async def configure_cloud_init(self, context): diff --git a/subiquity/server/controllers/tests/test_ad.py b/subiquity/server/controllers/tests/test_ad.py index 3c70c6f7..0976197f 100644 --- a/subiquity/server/controllers/tests/test_ad.py +++ b/subiquity/server/controllers/tests/test_ad.py @@ -19,16 +19,16 @@ from unittest import ( ) from subiquity.common.types import ( AdAdminNameValidation, - ADConnectionInfo, + AdConnectionInfo, AdDomainNameValidation, AdJoinResult, AdPasswordValidation, ) from subiquity.server.controllers.ad import ( - ADController, + AdController, AdValidators, ) -from subiquity.models.ad import ADModel +from subiquity.models.ad import AdModel from subiquitycore.tests.mocks import make_app @@ -134,8 +134,8 @@ class TestADValidation(TestCase): class TestAdJoin(IsolatedAsyncioTestCase): def setUp(self): self.app = make_app() - self.controller = ADController(self.app) - self.controller.model = ADModel() + self.controller = AdController(self.app) + self.controller.model = AdModel() async def test_never_join(self): # Calling join_result_GET has no effect if the model is not set. @@ -143,8 +143,8 @@ class TestAdJoin(IsolatedAsyncioTestCase): self.assertEqual(result, AdJoinResult.UNKNOWN) async def test_join_Unknown(self): - # Result remains UNKNOWN while ADController.join_domain is not called. - self.controller.model.set(ADConnectionInfo(domain_name='ubuntu.com', + # Result remains UNKNOWN while AdController.join_domain is not called. + self.controller.model.set(AdConnectionInfo(domain_name='ubuntu.com', admin_name='Helper', password='1234')) @@ -153,7 +153,7 @@ class TestAdJoin(IsolatedAsyncioTestCase): async def test_join_OK(self): # The equivalent of a successful POST - self.controller.model.set(ADConnectionInfo(domain_name='ubuntu.com', + self.controller.model.set(AdConnectionInfo(domain_name='ubuntu.com', admin_name='Helper', password='1234')) # Mimics a client requesting the join result. Blocking by default. @@ -163,7 +163,7 @@ class TestAdJoin(IsolatedAsyncioTestCase): self.assertEqual(await result, AdJoinResult.OK) async def test_join_Join_Error(self): - self.controller.model.set(ADConnectionInfo(domain_name='jubuntu.com', + self.controller.model.set(AdConnectionInfo(domain_name='jubuntu.com', admin_name='Helper', password='1234')) await self.controller.join_domain('this', 'AD Join') @@ -171,7 +171,7 @@ class TestAdJoin(IsolatedAsyncioTestCase): self.assertEqual(result, AdJoinResult.JOIN_ERROR) async def test_join_Pam_Error(self): - self.controller.model.set(ADConnectionInfo(domain_name='pubuntu.com', + self.controller.model.set(AdConnectionInfo(domain_name='pubuntu.com', admin_name='Helper', password='1234')) await self.controller.join_domain('this', 'AD Join') diff --git a/subiquity/server/server.py b/subiquity/server/server.py index 07b8c545..9b7f8264 100644 --- a/subiquity/server/server.py +++ b/subiquity/server/server.py @@ -259,7 +259,7 @@ class SubiquityServer(Application): "Identity", "SSH", "SnapList", - "AD", + "Ad", "Codecs", "Drivers", "TimeZone",