def test_defaults(): host_client = ResourceManagerClient() pub_ip_client = ResourceManagerClient(resource_type='public-addresses') priv_ip_client = ResourceManagerClient(resource_type='private-addresses') cobbler_url = "http://cobbler.example.com/cobbler_api" cobbler_user = "******" cobbler_password = "******" response_body = '''<?xml version="1.0"?> <methodResponse> <params> <param> <value><string>Some Value</string></value> </param> </params> </methodResponse> ''' distro_map = { 'centos': 'centos6-x86_64-raid0', 'rhel': 'rhel6u6-x86_64-raid0' } httpretty.register_uri(httpretty.POST, cobbler_url, body=response_body) pxe_manager = PxeManager(cobbler_url, cobbler_user, cobbler_password, host_client, pub_ip_client, priv_ip_client) for key, value in distro_map.iteritems(): assert pxe_manager.distro[key] == value
def test_find_resources(): client = ResourceManagerClient() field = 'some_field' value = 'some_value' url = client.endpoint response_body = "{\"_items\":[]}" httpretty.register_uri(httpretty.GET, url, body=response_body) client.find_resources(field, value)
def test_get(): client = ResourceManagerClient() resource = 'test_machine' response_body = '{"_id": "my_id"}' httpretty.register_uri(httpretty.GET, client.endpoint + "/" + resource, body=response_body) assert client.get_resource(resource) == json.loads(response_body)
def test_find_resources(): client = ResourceManagerClient() field = 'some_field' value = 'some_value' url = client.endpoint + "?where=" + field + "==" + urllib.quote("\"" + value + "\"") response_body = "{}" httpretty.register_uri(httpretty.GET, url, body=response_body) client.find_resources(field, value)
def test_update(): client = ResourceManagerClient() resource = "{\"hostname\":\"resource\"}" response_body = '{"_id": "my_id", "_etag":"2341341234"}' httpretty.register_uri(httpretty.GET, client.endpoint + "/resource", body=response_body) response_body = '{"_id": "my_id"}' httpretty.register_uri(httpretty.PATCH, client.endpoint + "/my_id", body=response_body) client.update_resource(resource)
def test_defaults(resource='machines'): client = ResourceManagerClient(resource) assert client.resource_type == resource defaults = dict( endpoint='http://127.0.0.1:5000/machines', resource_type='machines', key='hostname', auth=('admin', 'admin'), headers={'content-type': 'application/json'}, fields=["hostname", "owner", "state", "job_id", "_updated", "_id"]) for attribute, value in defaults.iteritems(): try: assert value == client.__getattribute__(attribute) except AssertionError: raise AssertionError("Default for {0} should be:{1}\n" "Received: {2}".format( attribute, client.__getattribute__(attribute), value))
def test_get_all_resources(): client = ResourceManagerClient() url = client.endpoint response_body = "{\"_items\":[]}" httpretty.register_uri(httpretty.GET, url, body=response_body) assert isinstance(client.get_all_resources(), list)
def test_init(): ResourceManagerClient()
def test_create(): client = ResourceManagerClient() resource = "{\"hostname\":\"resource\"}" httpretty.register_uri(httpretty.POST, client.endpoint, status=201) client.create_resource(resource)
'regex': r'a-\d\d-\w.qa1.eucalyptus-systems.com', 'mem': 137438953472, 'cpucores': 8, 'cpumhz': 2600, 'interfaces': [{ 'ratembps': 10000 }] } } with open(newhosts, "r") as file: collected = json.loads(file.read()) # client = ResourceManagerClient(endpoint="http://10.111.4.100:5000") # PRODUCTION client = ResourceManagerClient( endpoint="http://127.0.0.1:5000" ) # USE "http://10.111.4.100:5000" for production ourlist = client.get_all_resources() for item in ourlist: machine = client.get_resource(item['hostname']) # PRODUCTION for mtype in memtable: match = re.search(memtable[mtype]['regex'], item['hostname']) if match: if 'tags' not in machine.keys(): machine[u'tags'] = {} if item['hostname'] in collected['hosts'].keys(): print "{}: updating to {} (collected) (vs {} table)".format( item['hostname'], int(collected['hosts'][item['hostname']]) * 1024, memtable[mtype]['mem']) machine[u'tags'][u'memory'] = int(collected['hosts'][