cloudbridge
cloudbridge copied to clipboard
[WIP] Adding middleware support in factory
This adds support for middleware in factory, which then gets inherited by any provider object created by this factory.
Three options to add middleware from factory:
- Direct middleware add which will keep the same object across calls from any provider created by this factory after adding (in this example, the count will continue for all calls)
class SomeDummyClass(object):
count = start_count
@intercept(event_pattern="*", priority=2499)
def return_incremented(self, event_args, *args, **kwargs):
self.count += 1
return self.count
some_obj = SomeDummyClass()
factory.middleware.add(some_obj)
- Middleware constructor add which will create the middleware with the class and arguments when making a new middleware manager for the provider object (in this example, count will only keep track of calls within each provider):
class SomeDummyClassWithArgs(object):
def __init__(self, start, increment):
self.count = start
self.increment = increment
@intercept(event_pattern="*", priority=2499)
def return_incremented(self, event_args, *args, **kwargs):
self.count += self.increment
return self.count
factory = CloudProviderFactory()
factory.middleware.add_constructor(SomeDummyClassWithArgs,
start_count, increment)
and 3) adding events directly which will recreate a handler with the same callback function (bound methods will remain bound to their object)
def return_hello(event_args, *args, **kwargs):
return "hello"
factory = CloudProviderFactory()
factory.middleware.events.intercept("*", 2490, return_hello)
For all these scenarios, provider objects will inherit the events from the factory:
aws = factory.create_provider(ProviderList.AWS, {})
az = factory.create_provider(ProviderList.AZURE, {})
# Both providers will inherit all middleware/handlers added to the factory
Pull Request Test Coverage Report for Build 1500
- 361 of 377 (95.76%) changed or added relevant lines in 12 files are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage increased (+10.1%) to 88.855%
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
---|---|---|---|
cloudbridge/cloud/factory.py | 112 | 128 | 87.5% |
<!-- | Total: | 361 | 377 |
Totals | |
---|---|
Change from base Build 1470: | 10.1% |
Covered Lines: | 7292 |
Relevant Lines: | 7902 |
💛 - Coveralls
Codecov Report
Merging #195 into master will decrease coverage by
0.07%
. The diff coverage is94.42%
.
@@ Coverage Diff @@
## master #195 +/- ##
==========================================
- Coverage 88.03% 87.96% -0.08%
==========================================
Files 36 36
Lines 7775 7902 +127
Branches 854 868 +14
==========================================
+ Hits 6845 6951 +106
- Misses 594 610 +16
- Partials 336 341 +5
Impacted Files | Coverage Δ | |
---|---|---|
cloudbridge/cloud/providers/azure/services.py | 88.2% <100%> (ø) |
:arrow_up: |
cloudbridge/cloud/providers/aws/services.py | 90.09% <100%> (ø) |
:arrow_up: |
cloudbridge/cloud/providers/gcp/provider.py | 91.95% <100%> (ø) |
:arrow_up: |
cloudbridge/cloud/providers/aws/provider.py | 96.22% <100%> (ø) |
:arrow_up: |
cloudbridge/cloud/providers/mock/provider.py | 100% <100%> (ø) |
:arrow_up: |
cloudbridge/cloud/base/provider.py | 88.23% <100%> (ø) |
:arrow_up: |
cloudbridge/cloud/providers/openstack/provider.py | 88.46% <100%> (ø) |
:arrow_up: |
cloudbridge/cloud/base/services.py | 88.23% <100%> (ø) |
:arrow_up: |
cloudbridge/cloud/providers/openstack/services.py | 82.08% <100%> (ø) |
:arrow_up: |
cloudbridge/cloud/providers/gcp/services.py | 83.31% <100%> (ø) |
:arrow_up: |
... and 2 more |
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 ccafd0b...aa50481. Read the comment docs.