Skip to content
This repository has been archived by the owner on Jan 24, 2018. It is now read-only.

WIP: Bugfix: 'NoneType' object has no attribute 'get_transport' #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

WIP: Bugfix: 'NoneType' object has no attribute 'get_transport' #227

wants to merge 1 commit into from

Conversation

katyukha
Copy link
Contributor

Hello!

This is mostly bugfix PR, but I want also do some more refactoring of __execute method.
Can I do it in this PR? Or it is better to create separate PR?

Changes

  • partly refactored method ClouderModel.__execute
  • SSHEnvironment.__getattr__: if we define getattr we do not need to
    call super method, because getattr is called only if attribute is
    not found by other methods, such as: dict lookup, getattribute,
    etc.

Plans

  • Refactor ClouderModel.__execute
    • rename it to _execute, this allow to override it in inherited models, especially colouder.service
    • move code related to ClouderService to clouder.service model (this allow to avoid strange ifs like if self._name == 'clouder.service')
    • move code that parses and wraps cmd arg to separate method

- partly refactored method `ClouderModel.__execute`
- `SSHEnvironment.__getattr__`: if we define getattr we do not need to
call *super* method, because __getattr__ is called only if attribute is
not found by other methods, such as: __dict__ lookup, __getattribute__,
etc.
   - [SO question](http://stackoverflow.com/questions/3278077/difference-between-getattr-vs-getattribute)
   - [Py documentation](https://docs.python.org/2/reference/datamodel.html#object.__getattr__)
@codecov-io
Copy link

Codecov Report

Merging #227 into master will increase coverage by 0.11%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #227      +/-   ##
==========================================
+ Coverage   33.16%   33.28%   +0.11%     
==========================================
  Files          52       52              
  Lines        3902     3888      -14     
==========================================
  Hits         1294     1294              
+ Misses       2608     2594      -14
Impacted Files Coverage Δ
clouder/ssh/environment.py 27.52% <ø> (+0.97%) ⬆️
clouder/models/model.py 23.15% <0%> (+0.53%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b9c75b...5110400. Read the comment docs.

@@ -213,10 +213,6 @@ def __init__(self, *args, **kwargs):

def __getattr__(self, key):
""" Provide passthrough to paramiko Client while locking the conn """
try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, all attributes for the SSHEnvironment object will be inaccessible. This try/except block first attempts attributes on the current object, then escalates to paramiko. Did you run into some sort of name conflict or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No name conflicts, just attempt to make code cleaner and simpler...
I have some experience with __getattr__ and __getattribute__ method in few of my projects.

For example this and this do same thing, and both working.

__getattr__ method is called only if attribute is not found in usual way. Thus all normal attributes of SSHEnvironment object will be accessible. The super call is required if __getattribute__ method is used.

Simple repl test:

class MyObject(object):
    def __init__(self, obj):
        self.attr = 42
        self.obj = obj 

    def __getattr__(self, name):
        return getattr(self.obj, name)

class C2(object):
    def __init__(self):
        self.obj_attr = 81


obj = MyObject(C2())

print obj.attr      # output: 42
print obj.obj_attr  # output: 81

May be i have something missed?

Also i can revert this change in next commit...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants