def test_01_nano_handle(self): # successful nano-handle created with default options try: nano = bn.NanoHandle(license_file="./.BoonLogic.license") assert_equal(nano.license_id, 'default') except bn.BoonException as be: assert_false(False, 'test for default license_id failed') # clean house clean_nano_instances(nano) # successful nano-handle created with None specified for license_id, should equate to default try: nano = bn.NanoHandle(license_file=".BoonLogic.license", license_id=None) assert_equal(nano.license_id, 'default') except bn.BoonException as be: assert_false(False, 'test for license_id = None failed') # successful nano-handle created with non-default specified, license_id=localhost try: nano = bn.NanoHandle(license_file=".BoonLogic.license", license_id='sample-license') assert_equal(nano.license_id, 'sample-license') assert_equal(nano.api_key, 'sample-key') assert_equal(nano.api_tenant, 'sample-tenant') assert_equal(nano.server, 'http://samplehost:5007') except bn.BoonException as be: assert_false(False, 'test for license_id = localhost failed') # override license_id through environment os.environ['BOON_LICENSE_ID'] = 'sample-license' try: nano = bn.NanoHandle(license_file=".BoonLogic.license") assert_equal(nano.license_id, 'sample-license') assert_equal(nano.api_key, 'sample-key') assert_equal(nano.api_tenant, 'sample-tenant') assert_equal(nano.server, 'http://samplehost:5007') except bn.BoonException as be: assert_false(False, 'test for BOON_LICENSE_ID = sample-license failed') os.environ.pop('BOON_LICENSE_ID') # override BOON_API_KEY, BOON_API_TENANT and BOON_SERVER os.environ['BOON_API_KEY'] = 'new-key' os.environ['BOON_API_TENANT'] = 'new-tenant' os.environ['BOON_SERVER'] = 'new-server:9999' try: nano = bn.NanoHandle(license_file=".BoonLogic.license") assert_equal(nano.license_id, 'default') assert_equal(nano.api_key, 'new-key') assert_equal(nano.api_tenant, 'new-tenant') assert_equal(nano.server, 'new-server:9999') except bn.BoonException as be: assert_false(False, 'test for environment override failed') os.environ.pop('BOON_API_KEY') os.environ.pop('BOON_API_TENANT') os.environ.pop('BOON_SERVER')
def test_03_open_close(self): # allocate four nano handles and open an instance for each for license_file in [".BoonLogic.proxy", ".BoonLogic.license"]: nano_dict = dict() try: for cnt in range(1, 5): nano_key = 'nano-' + str(cnt) nano_inst = 'nano-instance-' + str(cnt) nano_dict[nano_key] = bn.NanoHandle(license_file=license_file) assert_equal(nano_dict[nano_key].license_id, 'default') success, response = nano_dict[nano_key].open_nano(nano_inst) assert_equal(success, True) assert_equal(response['instanceID'], nano_inst) except bn.BoonException as be: assert_false(False, 'creation of 4 nano handles failed') # create one more NanoHandle try: nano = bn.NanoHandle(license_file=license_file) assert_equal(nano.license_id, 'default') except bn.BoonException as be: assert_false(False, 'test for default license_id failed') # attaching to 1 more instance should cause an error success, response = nano.open_nano('1-too-many') assert_equal(success, False) assert_equal(response, '400: All nano instance objects are allocated (total number = 4)') # close an instance that doesn't exist, this involves creating two nano handles and point them at the # same instance. closing the first should succeed, the second should fail clean_nano_instances(nano) try: nano1 = bn.NanoHandle(license_file=license_file) nano2 = bn.NanoHandle(license_file=license_file) assert_equal(nano1.license_id, 'default') assert_equal(nano2.license_id, 'default') except bn.BoonException as be: assert_false(False, 'test for default license_id failed') success, response = nano1.open_nano('instance-1') assert_equal(success, True) success, response = nano2.open_nano('instance-1') assert_equal(success, True) # should succeed success, response = nano1.close_nano() assert_equal(success, True) # should fail success, response = nano2.close_nano() assert_equal(success, False)
def test_01_negative(self): # override server with a bad one os.environ['BOON_SERVER'] = 'not-a-server:9999' self.nano = bn.NanoHandle(license_file="./.BoonLogic.license") # simple_get with bad server success, response = bn.simple_get(self.nano, '/expert/v3/instance') assert_equal(success, False) assert_equal(response, 'request failed: No host specified.') # multipart_post with bad server success, response = bn.multipart_post(self.nano, '/expert/v3/instance') assert_equal(success, False) assert_equal(response, 'request failed: No host specified.') # simple_post with bad server success, response = bn.simple_post(self.nano, '/expert/v3/deleteInstance') assert_equal(success, False) assert_equal(response, 'request failed: No host specified.') # simple_delete with bad server success, response = bn.simple_delete(self.nano, '/expert/v3/deleteInstance') assert_equal(success, False) assert_equal(response, 'request failed: No host specified.')
def __init__(self): build_environment() try: self.nano = bn.NanoHandle(license_file="./.BoonLogic.license") assert_equal(self.nano.license_id, 'default') except bn.BoonException as be: assert_false(False, 'test for default license_id failed')
import boonnano as bn import json import sys import csv # # example of each boonnano SDK endpoint # # create new nano instance try: nano = bn.NanoHandle('default') except bn.BoonException as be: print(be) sys.exit(1) # open/attach to nano success, response = nano.open_nano('sample-instance') if not success: print("open_nano failed: {}".format(response)) sys.exit(1) # fetch the version information for this nano instance success, response = nano.get_version() if not success: print("get_version failed: {}".format(response)) sys.exit(1) print(json.dumps(response, indent=4)) # list the nano instances success, response = nano.nano_list()
def teardown(self): os.environ['BOON_SERVER'] = '' self.nano = bn.NanoHandle(license_file="./.BoonLogic.license") self.nano.close_nano()