Skip to content

Commit

Permalink
Merge pull request #646 from cderici/remove-not-implemented-functions
Browse files Browse the repository at this point in the history
#646

#### Description

This removes the stub functions that just raise `NotImplementedError`. Note that we still use that error for vaious sub-functionalities or corner cases that are yet to be implemented. This only removes the functions that stays in the code as stubs.

#### QA Steps

```sh
CI tests should pass.
```

#### Notes & Discussion

This also introduces `AbstractMethodError` for `@abstractmethod` functions to raise instead of raising the `NotImplementedError`.
  • Loading branch information
jujubot authored Mar 3, 2022
2 parents b9912fc + 335e39d commit 9ef8e6a
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 496 deletions.
40 changes: 0 additions & 40 deletions juju/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,6 @@ async def scale(self, scale=None, scale_change=None):
scale_change=scale_change)
])

def attach(self, resource_name, file_path):
"""Upload a file as a resource for this application.
:param str resource: Name of the resource
:param str file_path: Path to the file to upload
"""
raise NotImplementedError()

def collect_metrics(self):
"""Collect metrics on this application.
"""
raise NotImplementedError()

async def destroy_relation(self, local_relation, remote_relation):
"""Remove a relation to another application.
Expand Down Expand Up @@ -582,31 +567,6 @@ async def set_constraints(self, constraints):

return await app_facade.SetConstraints(application=self.name, constraints=constraints)

def set_meter_status(self, status, info=None):
"""Set the meter status on this status.
:param str status: Meter status, e.g. 'RED', 'AMBER'
:param str info: Extra info message
"""
raise NotImplementedError()

def set_plan(self, plan_name):
"""Set the plan for this application, effective immediately.
:param str plan_name: Name of plan
"""
raise NotImplementedError()

def update_allocation(self, allocation):
"""Update existing allocation for this application.
:param int allocation: The allocation to set
"""
raise NotImplementedError()

async def refresh(
self, channel=None, force=False, force_series=False, force_units=False,
path=None, resources=None, revision=None, switch=None):
Expand Down
62 changes: 0 additions & 62 deletions juju/client/jujudata.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,68 +18,6 @@ class NoModelException(Exception):
class JujuData:
__metaclass__ = abc.ABCMeta

@abc.abstractmethod
def current_controller(self):
'''Return the current controller name'''
raise NotImplementedError()

@abc.abstractmethod
def controllers(self):
'''Return all the currently known controllers as a dict
mapping controller name to a dict containing the
following string keys:
uuid: The UUID of the controller
api-endpoints: A list of host:port addresses for the controller.
ca-cert: the PEM-encoded CA cert of the controller (optional)
This is compatible with the "controllers" entry in the YAML-unmarshaled data
stored in ~/.local/share/juju/controllers.yaml.
'''
raise NotImplementedError()

@abc.abstractmethod
def models(self):
'''Return all the currently known models as a dict
containing a key for each known controller,
each holding a dict value containing an optional "current-model"
key (the name of the current model for that controller,
if there is one), and a dict mapping fully-qualified
model names to a dict containing a "uuid" key with the
key for that model.
This is compatible with the YAML-unmarshaled data
stored in ~/.local/share/juju/models.yaml.
'''
raise NotImplementedError()

@abc.abstractmethod
def accounts(self):
'''Return the currently known accounts, as a dict
containing a key for each known controller, with
each value holding a dict with the following keys:
user: The username to use when logging into the controller (str)
password: The password to use when logging into the controller (str, optional)
'''
raise NotImplementedError()

@abc.abstractmethod
def cookies_for_controller(self, controller_name):
'''Return the cookie jar to use when connecting to the
controller with the given name.
:return http.cookiejar.CookieJar
'''
raise NotImplementedError()

@abc.abstractmethod
def current_model(self, controller_name=None, model_only=False):
'''Return the current model, qualified by its controller name.
If controller_name is specified, the current model for
that controller will be returned.
If model_only is true, only the model name, not qualified by
its controller name, will be returned.
'''
raise NotImplementedError()

def parse_model(self, model):
"""Split the given model_name into controller and model parts.
If the controller part is empty, the current controller will be used.
Expand Down
8 changes: 5 additions & 3 deletions juju/client/proxy/proxy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from abc import abstractmethod

from juju.errors import AbstractMethodError


class ProxyNotConnectedError(Exception):
pass
Expand All @@ -12,12 +14,12 @@ class Proxy():

@abstractmethod
def connect(self):
raise NotImplementedError()
raise AbstractMethodError()

@abstractmethod
def close(self):
raise NotImplementedError()
raise AbstractMethodError()

@abstractmethod
def socket(self):
raise NotImplementedError()
raise AbstractMethodError()
40 changes: 0 additions & 40 deletions juju/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,6 @@ async def enable_user(self, username):
entity = client.Entity(tag.user(username))
return await user_facade.EnableUser(entities=[entity])

def kill(self):
"""Forcibly terminate all machines and other associated resources for
this controller.
"""
raise NotImplementedError()

async def cloud(self, name=None):
"""Get Cloud
Expand Down Expand Up @@ -576,39 +569,6 @@ async def list_models(self, username=None, all=False):
uuids = await self.model_uuids(username, all)
return sorted(uuids.keys())

def get_payloads(self, *patterns):
"""Return list of known payloads.
:param str *patterns: Patterns to match against
Each pattern will be checked against the following info in Juju::
- unit name
- machine id
- payload type
- payload class
- payload id
- payload tag
- payload status
"""
raise NotImplementedError()

def login(self):
"""Log in to this controller.
"""
raise NotImplementedError()

def logout(self, force=False):
"""Log out of this controller.
:param bool force: Don't fail even if user not previously logged in
with a password
"""
raise NotImplementedError()

async def get_current_user(self, secret_key=None):
"""Returns the user object associated with the current connection.
:param str secret_key: Issued by juju when add or reset user
Expand Down
4 changes: 4 additions & 0 deletions juju/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@ class JujuApplicationConfigError(JujuConfigError):

class JujuModelConfigError(JujuConfigError):
pass


class AbstractMethodError(Exception):
pass
74 changes: 0 additions & 74 deletions juju/juju.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,74 +8,12 @@ class Juju(object):
def __init__(self, jujudata=None):
self.jujudata = jujudata or FileJujuData()

def add_cloud(self, name, definition, replace=False):
"""Add a user-defined cloud to Juju from among known cloud types.
:param str name: Name of cloud
:param dict definition: Cloud definition
Example cloud definition, as yaml::
type: openstack
auth-types: [ userpass ]
regions:
london:
endpoint: https://london.mycloud.com:35574/v3.0/
"""
raise NotImplementedError()

def agree(self, *terms):
"""Agree to the terms of a charm.
:param str *terms: Terms to agree to
"""
raise NotImplementedError()

def autoload_credentials(self):
"""Finds cloud credentials and caches them for use by Juju when
bootstrapping.
"""
raise NotImplementedError()

def get_clouds(self):
"""Return list of all available clouds.
"""
raise NotImplementedError()

def get_controllers(self):
"""Return list of all available controllers.
"""
return self.jujudata.controllers()

def get_plans(self, charm_url):
"""Return list of plans available for the specified charm.
:param str charm_url: Charm url
"""
raise NotImplementedError()

def register(self, registration_string):
"""Register a user to a controller.
:param str registration_string: The registration string
"""
raise NotImplementedError()

def get_cloud(self, name):
"""Get a cloud by name.
:param str name: Name of cloud
"""
raise NotImplementedError()

async def get_controller(self, name, include_passwords=False):
"""Get a controller by name.
Expand All @@ -96,15 +34,3 @@ async def get_controller(self, name, include_passwords=False):
controller = Controller()
await controller.connect(name)
return controller

def update_clouds(self):
"""Update public cloud info available to Juju.
"""
raise NotImplementedError()

def version(self):
"""Return the Juju version.
"""
raise NotImplementedError()
18 changes: 0 additions & 18 deletions juju/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ async def destroy(self, force=False):
'machine', self.id, 'remove')
remove = destroy

def run(self, command, timeout=None):
"""Run command on this machine.
:param str command: The command to run
:param int timeout: Time to wait before command is considered failed
"""
raise NotImplementedError()

async def get_annotations(self):
"""Get annotations on this machine.
Expand Down Expand Up @@ -171,15 +162,6 @@ async def ssh(
# stdout is a bytes-like object, returning a string might be more useful
return stdout.decode()

def status_history(self, num=20, utc=False):
"""Get status history for this machine.
:param int num: Size of history backlog
:param bool utc: Display time as UTC in RFC3339 format
"""
raise NotImplementedError()

@property
def agent_status(self):
"""Returns the current Juju agent status string.
Expand Down
Loading

0 comments on commit 9ef8e6a

Please sign in to comment.