Skip to content

Commit

Permalink
Delete API (un-publish) should clear the entry from DB instead of cha…
Browse files Browse the repository at this point in the history
…nging

admin-state down. Add test case to verify service entry is removed after
delete API is invoked.

Change-Id: I410f3cd9d9f568e5c52bc5c4a407d9efc2b7eb07
Closes-Bug: #1514589
(cherry picked from commit d57371a)
  • Loading branch information
Deepinder Setia committed Nov 10, 2015
1 parent cfabb31 commit ddef40e
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
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,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
Original file line number Diff line number Diff line change
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 ddef40e

Please sign in to comment.