Skip to content

Commit

Permalink
Merge pull request #35 from ToxicWar/feature/get-resclass-by-counter-…
Browse files Browse the repository at this point in the history
…unit

Get resclass by counter unit from package scheme
  • Loading branch information
ToxicWar authored Dec 8, 2017
2 parents 3e9966f + a515453 commit 96673ee
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
22 changes: 18 additions & 4 deletions apsconnectcli/apsconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,9 @@ def install_frontend(self, source, oauth_key, oauth_secret, backend_url, setting
# Create counters resource types
counters = _get_counters(tenant_schema_path)

for counter in counters:
for counter, schema in counters.items():
payload = {
'resclass_name': "rc.saas.resource.unit",
'resclass_name': _get_resclass_name(schema['unit']),
'name': '{} {}'.format(connector_name, counter),
'act_params': [
{
Expand All @@ -527,9 +527,9 @@ def install_frontend(self, source, oauth_key, oauth_secret, backend_url, setting
# Create parameters resource types
parameters = _get_parameters(tenant_schema_path)

for parameter in parameters:
for parameter, schema in parameters.items():
payload = {
'resclass_name': "rc.saas.resource.unit",
'resclass_name': _get_resclass_name(schema['unit']),
'name': '{} {}'.format(connector_name, parameter),
'act_params': [
{
Expand Down Expand Up @@ -1037,6 +1037,20 @@ def _get_parameters(tenant_schema_path):
return parameters


def _get_resclass_name(unit):
resclass_name = {
'Kbit/sec': 'rc.saas.resource.kbps',
'kb': 'rc.saas.resource',
'mb-h': 'rc.saas.resource.mbh',
'mhz': 'rc.saas.resource.mhz',
'mhzh': 'rc.saas.resource.mhzh',
'unit': 'rc.saas.resource.unit',
'unit-h': 'rc.saas.resource.unith'
}.get(unit)

return resclass_name or 'rc.saas.resource.unit'


def _get_properties(schema_path):
with open(schema_path) as file:
try:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
setup(
name='apsconnectcli',
author='Ingram Micro',
version='1.7.16',
version='1.7.17',
keywords='aps apsconnect connector automation',
extras_require={
':python_version<="2.7"': ['backports.tempfile==1.0']},
Expand Down
31 changes: 31 additions & 0 deletions tests/test_apsconnect_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
_osaapi_raise_for_status,
_get_k8s_api_client,
_get_properties,
_get_resclass_name,
_cluster_probe_connection,
_create_secret,
_create_deployment,
Expand Down Expand Up @@ -558,3 +559,33 @@ def test_force_creation(self):
fake_core_v1.delete_namespaced_service.assert_called_once_with(**deletion_kwargs)
fake_core_v1.create_namespaced_service.assert_called_once_with(
namespace=namespace, body=service)


class ResClassTest(TestCase):
"""Tests for _get_resclass_name()"""

def test_get_resclass_name_for_current_units(self):
data = {
'Kbit/sec': 'rc.saas.resource.kbps',
'kb': 'rc.saas.resource',
'mb-h': 'rc.saas.resource.mbh',
'mhz': 'rc.saas.resource.mhz',
'mhzh': 'rc.saas.resource.mhzh',
'unit': 'rc.saas.resource.unit',
'unit-h': 'rc.saas.resource.unith'
}

for key, value in data.items():
self.assertEqual(_get_resclass_name(key), value)

def test_get_resclass_name_for_new_unit(self):
self.assertEqual(
_get_resclass_name('new-unit'),
'rc.saas.resource.unit',
)

def test_get_resclass_name_witout_unit(self):
self.assertEqual(
_get_resclass_name(''),
'rc.saas.resource.unit',
)

0 comments on commit 96673ee

Please sign in to comment.