Removing host/port, already in listen_address

This commit is contained in:
Josh Gachnang 2014-03-19 11:14:45 -07:00
parent 1ad55bc789
commit 56a0ed37a4
5 changed files with 17 additions and 33 deletions

View File

@ -109,12 +109,10 @@ class TeethAgentHeartbeater(threading.Thread):
class TeethAgent(object):
def __init__(self, api_url, listen_address, ipaddr, port=9999):
def __init__(self, api_url, listen_address):
self.api_url = api_url
self.api_client = overlord_agent_api.APIClient(self.api_url)
self.listen_address = listen_address
self.ipaddr = ipaddr
self.port = port
self.mode_implementation = None
self.version = pkg_resources.get_distribution('teeth-agent').version
self.api = app.VersionSelectorApplication(self)
@ -236,5 +234,5 @@ def _load_mode_implementation(mode_name):
return mgr.driver
def build_agent(api_url, listen_host, listen_port, ipaddr):
return TeethAgent(api_url, (listen_host, listen_port), ipaddr)
def build_agent(api_url, listen_host, listen_port):
return TeethAgent(api_url, (listen_host, listen_port))

View File

@ -38,17 +38,7 @@ def run():
type=int,
help='The port to listen on')
parser.add_argument('--ipaddr',
required=True,
help='The external IP address to advertise to ironic')
parser.add_argument('--port',
required=False,
help='The external port the agent is listening on')
args = parser.parse_args()
agent.build_agent(args.api_url,
args.listen_host,
args.listen_port,
args.ipaddr,
args.port).run()
args.listen_port).run()

View File

@ -46,13 +46,13 @@ class APIClient(object):
headers=request_headers,
data=data)
def heartbeat(self, uuid, ipaddr, port):
def heartbeat(self, uuid, listen_address):
path = '/{api_version}/nodes/{uuid}/vendor_passthru/heartbeat'.format(
api_version=self.api_version,
uuid=uuid
)
data = {
'agent_url': self._get_agent_url(ipaddr, port)
'agent_url': self._get_agent_url(listen_address)
}
try:
response = self._request('POST', path, data=data)
@ -98,5 +98,5 @@ class APIClient(object):
'{0}'.format(content))
return content['node']
def _get_agent_url(self, ipaddr, port):
return "http://{0}:{1}".format(ipaddr, port)
def _get_agent_url(self, listen_address):
return "http://{0}:{1}".format(listen_address[0], listen_address[1])

View File

@ -120,8 +120,7 @@ class TestBaseAgent(unittest.TestCase):
def setUp(self):
self.encoder = encoding.RESTJSONEncoder(indent=4)
self.agent = agent.TeethAgent('https://fake_api.example.org:8081/',
('localhost', 9999),
'192.168.1.1')
('localhost', 9999))
def assertEqualEncoded(self, a, b):
# Evidently JSONEncoder.default() can't handle None (??) so we have to

View File

@ -46,9 +46,10 @@ class TestBaseTeethAgent(unittest.TestCase):
self.api_client.session.request = mock.Mock()
self.api_client.session.request.return_value = response
heartbeat_before = self.api_client.heartbeat(uuid='fake-uuid',
ipaddr='42.42.42.42',
port=9999)
heartbeat_before = self.api_client.heartbeat(
uuid='fake-uuid',
listen_address=('42.42.42.42', '9999')
)
self.assertEqual(heartbeat_before, expected_heartbeat_before)
@ -64,8 +65,7 @@ class TestBaseTeethAgent(unittest.TestCase):
self.assertRaises(errors.HeartbeatError,
self.api_client.heartbeat,
uuid='fake-uuid',
ipaddr='42.42.42.42',
port=9999)
listen_address=('42.42.42.42', '9999'))
def test_heartbeat_invalid_status_code(self):
response = httmock.response(status_code=404)
@ -75,8 +75,7 @@ class TestBaseTeethAgent(unittest.TestCase):
self.assertRaises(errors.HeartbeatError,
self.api_client.heartbeat,
uuid='fake-uuid',
ipaddr='42.42.42.42',
port=9999)
listen_address=('42.42.42.42', '9999'))
def test_heartbeat_missing_heartbeat_before_header(self):
response = httmock.response(status_code=204)
@ -86,8 +85,7 @@ class TestBaseTeethAgent(unittest.TestCase):
self.assertRaises(errors.HeartbeatError,
self.api_client.heartbeat,
uuid='fake-uuid',
ipaddr='42.42.42.42',
port=9999)
listen_address=('42.42.42.42', '9999'))
def test_heartbeat_invalid_heartbeat_before_header(self):
response = httmock.response(status_code=204, headers={
@ -99,8 +97,7 @@ class TestBaseTeethAgent(unittest.TestCase):
self.assertRaises(errors.HeartbeatError,
self.api_client.heartbeat,
uuid='fake-uuid',
ipaddr='42.42.42.42',
port=9999)
listen_address=('42.42.42.42', '9999'))
def test_lookup_node(self):
response = httmock.response(status_code=200, content={