Skip to content

Commit

Permalink
Merge "Delete API (un-publish) should clear the entry from DB instead…
Browse files Browse the repository at this point in the history
… of changing admin-state down. Add test case to verify service entry is removed after delete API is invoked." into R2.20
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Nov 17, 2015
2 parents e9e0ece + ddef40e commit d28dc0c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/discovery/disc_server.py
Expand Up @@ -860,8 +860,7 @@ def service_http_delete(self, id):
if not entry:
bottle.abort(405, 'Unknown service')

entry['admin_state'] = 'down'
self._db_conn.update_service(service_type, service_id, entry)
self._db_conn.delete_service(entry)

self.syslog('delete service=%s, sid=%s, info=%s'
% (service_type, service_id, entry))
Expand Down
29 changes: 29 additions & 0 deletions src/discovery/tests/test_publish.py
Expand Up @@ -327,3 +327,32 @@ def test_publish_client_lib(self):

entry = response['services'][0]
self.assertEqual(entry['status'], 'up')

def test_un_publish_json(self):
service_type = 'foobar'
payload = {
'%s' % service_type: { "ip-addr" : "1.1.1.1", "port" : "1234" }
}
puburl = '/publish/test_discovery'
(code, msg) = self._http_post(puburl, json.dumps(payload))
self.assertEqual(code, 200)

time.sleep(1)
(code, msg) = self._http_get('/services.json')
self.assertEqual(code, 200)

response = json.loads(msg)
self.assertEqual(len(response['services']), 1)
self.assertEqual(response['services'][0]['service_type'], service_type)

# unpublish (service-id:service-type)
puburl = '/service/test_discovery:foobar'
(code, msg) = self._http_delete(puburl, json.dumps({}))
self.assertEqual(code, 200)

time.sleep(1)
(code, msg) = self._http_get('/services.json')
self.assertEqual(code, 200)

response = json.loads(msg)
self.assertEqual(len(response['services']), 0)

0 comments on commit d28dc0c

Please sign in to comment.