def test_start(load_config_dict_mock, pre_add_host_mock, fire_provisioned_even_mock, get_instance_size_mapping_mock, dbm, valid_ami): """ Test ResourceAdapter.start() workflow """ get_instance_size_mapping_mock.return_value = 8 load_config_dict_mock.return_value = { 'awsaccesskey': 'the_key', 'awssecretkey': 'the_secret', 'keypair': 'the_keypair', 'ami': valid_ami, 'use_instance_hostname': 'true', 'instancetype': 'the_instancetype' } with dbm.session() as session: adapter = Aws(addHostSession='123EXAMPLE') # override default sleep time adapter.LAUNCH_INITIAL_SLEEP_TIME = 0.0 hardwareprofile = HardwareProfilesDbHandler().getHardwareProfile( session, 'aws2' ) softwareprofile = SoftwareProfilesDbHandler().getSoftwareProfile( session, 'compute' ) addNodesRequest = { 'count': 2, 'hardwareProfile': hardwareprofile.name, 'softwareProfile': softwareprofile.name, } nodes = adapter.start( addNodesRequest, session, hardwareprofile, dbSoftwareProfile=softwareprofile ) assert nodes and isinstance(nodes, list) and \ isinstance(nodes[0], Node) assert nodes[0].instance.instance if len(nodes) > 1: assert nodes[1].instance.instance pre_add_host_mock.assert_called() fire_provisioned_even_mock.assert_called()
def test_start_update_node(load_config_dict_mock, pre_add_host_mock, fire_provisioned_event_mock, dbm, valid_ami): configDict = { 'awsaccesskey': 'the_key', 'awssecretkey': 'the_secret', 'ami': valid_ami, 'use_instance_hostname': 'true', } load_config_dict_mock.return_value = configDict with dbm.session() as session: addHostSession = '123EXAMPLE' adapter = Aws(addHostSession=addHostSession) # override default sleep time adapter.LAUNCH_INITIAL_SLEEP_TIME = 0.0 count = 3 hardwareprofile = HardwareProfilesDbHandler().getHardwareProfile( session, 'aws2' ) softwareprofile = SoftwareProfilesDbHandler().getSoftwareProfile( session, 'compute' ) # create instances to be associated with nodes conn = boto.connect_ec2(configDict['awsaccesskey'], configDict['awssecretkey']) conn.run_instances( configDict['ami'], min_count=count, max_count=count ) # get newly created instances instances = conn.get_only_instances() # intialize 'addNodesRequest' addNodesRequest = { 'nodeDetails': [], } for instance in instances: addNodesRequest['nodeDetails'].append({ 'name': instance.private_dns_name, 'metadata': { 'ec2_instance_id': instance.id, 'ec2_ipaddress': instance.private_ip_address, } }) # call Aws.start() with instance metadata nodes = adapter.start( addNodesRequest, session, hardwareprofile, dbSoftwareProfile=softwareprofile ) assert nodes and len(nodes) == count assert isinstance(nodes[0], Node) assert nodes[0].softwareprofile.name == softwareprofile.name assert nodes[0].hardwareprofile.name == hardwareprofile.name assert nodes[0].addHostSession == addHostSession fire_provisioned_event_mock.assert_called() pre_add_host_mock.assert_called()