def test_unused_ip(self): with contextlib.nested( mock.patch("mimic.engine.foreman_helper.get_remote_data", mock.MagicMock(return_value={"ip": "192.168.10.3"})), mock.patch("mimic.db.api.get_instance", mock.MagicMock(return_value=utils.FakeDBAPI())) ): foreman_helper.unused_ip("00:11:22:33:44:55")
def build_host_data(mac, local, ip, build=True): hosts_num = foreman_helper.hosts() or {} if not ip: ipaddr = foreman_helper.unused_ip(mac) else: ipaddr = ip if len(hosts_num) == 0: hostname = "master" else: hostname = "us" + str(len(hosts_num) + 1) host_info = { 'name': hostname, 'ip': ipaddr, 'mac': mac, 'build': build } hg = foreman_helper.host_groups() role = "master" if local == "no": hostgroup_id = judgement.judge_hostgroup() else: hostgroup_id = hg['local'] for ro in hg: if hg[ro] == hostgroup_id: role = ro drivers = _load_drivers() host_info['hostgroup_id'] = hostgroup_id for driver in drivers: if role in driver.role: driver.action(len(hosts_num) + 1, host_info['name'], ip=ipaddr, role=hostgroup_id) LOG.info("Server To Post: %s" % host_info) return jsonutils.loads(foreman_helper.create_host(host_info))