Skip to content

Commit

Permalink
Merge "Remove ifmap code from api server"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Feb 24, 2017
2 parents c1ee317 + 44b851e commit 092b1e9
Show file tree
Hide file tree
Showing 55 changed files with 303 additions and 3,221 deletions.
16 changes: 4 additions & 12 deletions src/api-lib/vnc_api.py
Expand Up @@ -742,8 +742,8 @@ def _read_args_to_id(self, res_type, fq_name=None, fq_name_str=None,
if fq_name_str:
return (True, self.fq_name_to_id(res_type, fq_name_str.split(':')))
if ifmap_id:
return (True, self.ifmap_to_id(ifmap_id))
#end _read_args_to_id
return (False, "ifmap_id is no longer supported")
# end _read_args_to_id

def _request_server(self, op, url, data=None, retry_on_error=True,
retry_after_authn=False, retry_count=30):
Expand Down Expand Up @@ -1009,16 +1009,8 @@ def id_to_fq_name_type(self, id):
# This is required only for helping ifmap-subscribers using rest publish
@check_homepage
def ifmap_to_id(self, ifmap_id):
json_body = json.dumps({'ifmap_id': ifmap_id})
uri = self._action_uri['ifmap-to-id']
try:
content = self._request_server(rest.OP_POST, uri, data=json_body)
except HttpError as he:
if he.status_code == 404:
return None

return json.loads(content)['uuid']
#end ifmap_to_id
return None
# end ifmap_to_id

def obj_to_json(self, obj):
return json.dumps(obj, default=self._obj_serializer_all)
Expand Down
2 changes: 0 additions & 2 deletions src/config/api-server/SConscript
Expand Up @@ -55,8 +55,6 @@ for file in setup_sources:
local_sources = [
'__init__.py',
'vnc_cfg_api_server.py',
'vnc_ifmap.py',
'vnc_ifmap_client.py',
'vnc_db.py',
'vnc_cfg_types.py',
'vnc_auth.py',
Expand Down
12 changes: 0 additions & 12 deletions src/config/api-server/contrail-api.conf
Expand Up @@ -2,8 +2,6 @@
log_file = /var/log/contrail/contrail-api.log
log_level = SYS_NOTICE
log_local = 1
# ifmap_username = api-server
# ifmap_password = api-server
cassandra_server_list = 127.0.0.1:9160
disc_server_ip = 127.0.0.1
disc_server_port = 5998
Expand All @@ -22,16 +20,6 @@ disc_server_port = 5998
# release under R1.05 does not support that optimization (especially for port)
# list_optimization_enabled = False

[IFMAP_SERVER]
# IF-MAP server configuration
# Listen IP and port
ifmap_listen_ip = 0.0.0.0
ifmap_listen_port = 8443
# Key ans certificate files path. If not set automatically create
ifmap_key_path = /var/lib/contrail/api-server/ifmap-cert/key
ifmap_cert_path = /var/lib/contrail/api-server/ifmap-cert/cert
# Credentials: user:passwd[,user:passwd]
ifmap_credentials = control:secret

[SANDESH]
#sandesh_ssl_enable=false
Expand Down
6 changes: 1 addition & 5 deletions src/config/api-server/contrail-config.rules
@@ -1,6 +1,2 @@
{ "Rules": [
{"processname": "contrail-api", "process_state": "PROCESS_STATE_STOPPED", "action": "sudo service ifmap restart"},
{"processname": "contrail-api", "process_state": "PROCESS_STATE_EXITED", "action": "sudo service ifmap restart"},
{"processname": "contrail-api", "process_state": "PROCESS_STATE_FATAL", "action": "sudo service ifmap restart"}
]
{ "Rules": [ ]
}
105 changes: 4 additions & 101 deletions src/config/api-server/db_manage.py
Expand Up @@ -16,10 +16,6 @@
import cfgm_common
from cfgm_common import vnc_cgitb
from cfgm_common.utils import cgitb_hook
from cfgm_common.ifmap.client import client
from cfgm_common.ifmap.request import NewSessionRequest
from cfgm_common.ifmap.response import newSessionResult
from cfgm_common.imid import ifmap_read, parse_search_result
from cfgm_common.vnc_cassandra import VncCassandraClient
import pycassa
import utils
Expand All @@ -44,8 +40,6 @@ class CassWrongRFError(AuditError): pass
class FQNIndexMissingError(AuditError): pass
class FQNStaleIndexError(AuditError): pass
class FQNMismatchError(AuditError): pass
class IfmapMissingIdentifiersError(AuditError): pass
class IfmapExtraIdentifiersError(AuditError): pass
class MandatoryFieldsMissingError(AuditError): pass
class IpSubnetMissingError(AuditError): pass
class VirtualNetworkMissingError(AuditError): pass
Expand Down Expand Up @@ -136,12 +130,6 @@ def _parse_args(self, args_str):
parser.add_argument(
"--debug", help="Run in debug mode, default False",
action='store_true', default=False)
parser.add_argument(
"--ifmap-servers", nargs='*',
help="List of ifmap-ip:ifmap-port, default from api-conf")
parser.add_argument(
"--ifmap-credentials",
help="<username>:<password> for read-only user")
parser.add_argument("--cassandra-user")
parser.add_argument("--cassandra-password")

Expand Down Expand Up @@ -481,14 +469,11 @@ def check_rabbitmq_queue(self):
# end check_rabbitmq_queue

@checker
def check_fq_name_uuid_ifmap_match(self):
# ensure items in obj-fq-name-table match to
# a. obj-uuid-table, b. local ifmap server
def check_fq_name_uuid_match(self):
# ensure items in obj-fq-name-table match to obj-uuid-table
ret_errors = []
logger = self._logger

self._connect_to_ifmap_servers()

obj_fq_name_table = self._cf_dict['obj_fq_name_table']
obj_uuid_table = self._cf_dict['obj_uuid_table']
fq_name_table_all = []
Expand Down Expand Up @@ -539,52 +524,8 @@ def check_fq_name_uuid_ifmap_match(self):
'Extra object %s %s %s in obj_uuid_table'
%(obj_type, fq_name_str, obj_uuid)))

for mapclient in self._mapclients:
all_ifmap_idents = []
search_results = parse_search_result(
ifmap_read(
mapclient,
'contrail:config-root:root',
srch_meta=None,
result_meta='contrail:id-perms'
)
)
# search_results is in form of
# [ ({'config-root': 'root'}, <Element metadata at 0x1e19b48>)
# ({'config-root': 'root',
# 'global-system-config': 'default-global-system-config'},
# <Element metadata at 0x1e19680>) ]
# convert it into set of identifiers
for ident_s, meta in search_results:
# ref to same type appears as list of idents
# flatten so set can be used
for ident in ident_s.values():
if type(ident) == list:
all_ifmap_idents.extend(ident)
else:
all_ifmap_idents.append(ident)
all_ifmap_idents = set(all_ifmap_idents)
all_cassandra_idents = set([item[1] for item in uuid_table_all])
logger.debug("Got %d idents from %s server",
len(all_ifmap_idents), mapclient._client__url[0])

extra = all_ifmap_idents - all_cassandra_idents
if (len(extra) == 1) and (extra == set(['root'])):
pass # good
else:
ret_errors.append(IfmapExtraIdentifiersError(
'Extra identifiers %s in ifmap %s vs obj_uuid_table'
%(extra, mapclient._client__url[0])))

extra = all_cassandra_idents - all_ifmap_idents
if extra:
ret_errors.append(IfmapMissingIdentifiersError(
'Missing identifiers %s in ifmap %s vs obj_uuid_table.\n' \
%(extra, mapclient._client__url[0])))


return ret_errors
# end check_fq_name_uuid_ifmap_match
# end check_fq_name_uuid_match

@checker
def check_obj_mandatory_fields(self):
Expand Down Expand Up @@ -1020,44 +961,6 @@ def set_reserved_addrs_in_cassandra(vn_id, fq_name_str):
return ret_errors
# end _addr_alloc_process_ip_objects

def _connect_to_ifmap_servers(self):
self._mapclients = []
NAMESPACES = {
'env': "http://www.w3.org/2003/05/soap-envelope",
'ifmap': "http://www.trustedcomputinggroup.org/2010/IFMAP/2",
'meta':
"http://www.trustedcomputinggroup.org/2010/IFMAP-METADATA/2",
'contrail': "http://www.contrailsystems.com/vnc_cfg.xsd"
}
# pick ifmap servers from args to this utility and if absent
# pick it from contrail-api conf file
if self._args.ifmap_servers:
ifmap_ips_ports = [(ip_port.split(':'))
for ip_port in self._args.ifmap_servers]
else:
ifmap_ips_ports = [(self._api_args.ifmap_listen_ip,
str(self._api_args.ifmap_listen_port))]
if self._args.ifmap_credentials:
ifmap_user, ifmap_passwd = self._args.ifmap_credentials.split(':')
else:
ifmap_user, ifmap_passwd = self._api_args.ifmap_credentials[0]

for ifmap_ip, ifmap_port in ifmap_ips_ports:
mapclient = client((ifmap_ip, ifmap_port),
ifmap_user, ifmap_passwd,
NAMESPACES)
connected = False
while not connected:
try:
result = mapclient.call('newSession', NewSessionRequest())
connected = True
except socket.error as e:
time.sleep(3)

mapclient.set_session_id(newSessionResult(result).get_session_id())
mapclient.set_publisher_id(newSessionResult(result).get_publisher_id())
self._mapclients.append(mapclient)
# end _connect_to_ifmap_servers
# end class DatabaseChecker


Expand Down Expand Up @@ -1439,7 +1342,7 @@ def db_check(args_str=''):
db_checker.check_zk_mode_and_node_count()
db_checker.check_cassandra_keyspace_replication()
db_checker.check_obj_mandatory_fields()
db_checker.check_fq_name_uuid_ifmap_match()
db_checker.check_fq_name_uuid_match()
db_checker.check_subnet_uuid()
db_checker.check_subnet_addr_alloc()
db_checker.check_route_targets_id()
Expand Down
1 change: 0 additions & 1 deletion src/config/api-server/requirements.txt
Expand Up @@ -3,7 +3,6 @@ vnc_api
discoveryclient
sandesh
sandesh-common
lxml>=2.3.3
gevent==1.1a2
geventhttpclient==1.0a
pycassa>=1.7.2
Expand Down
9 changes: 0 additions & 9 deletions src/config/api-server/setup.py
Expand Up @@ -36,15 +36,6 @@ def run(self):
package_data={'': ['*.html', '*.css', '*.xml']},
zip_safe=False,
long_description="VNC Configuration API Server Implementation",
install_requires=[
'lxml>=2.3.2',
'gevent>=0.13.6',
'geventhttpclient>=1.0a',
'pycassa>=1.7.2',
'netaddr>=0.7.5',
'bitarray>=0.8.0',
'psutil>=0.6.0',
],
entry_points = {
# Please update sandesh/common/vns.sandesh on process name change
'console_scripts' : [
Expand Down
1 change: 1 addition & 0 deletions src/config/api-server/test-requirements.txt
@@ -1,4 +1,5 @@
ipdb
lxml>=2.3.3
python-subunit
testrepository
flexmock
Expand Down
37 changes: 5 additions & 32 deletions src/config/api-server/tests/test_case.py
Expand Up @@ -9,7 +9,6 @@

from vnc_api import vnc_api
from cfgm_common import vnc_rdbms
import cfgm_common.ifmap.client as ifmap_client
from test_utils import *
import test_common

Expand Down Expand Up @@ -65,11 +64,11 @@ def _create_vn_ri_vmi(self, obj_count=1):
return vn_objs, ipam_objs, ri_objs, vmi_objs
# end _create_vn_ri_vmi

def assert_ifmap_doesnt_have_ident(self, test_obj):
self.assertTill(self.ifmap_doesnt_have_ident, obj=test_obj)
def assert_vnc_db_doesnt_have_ident(self, test_obj):
self.assertTill(self.vnc_db_doesnt_have_ident, obj=test_obj)

def assert_ifmap_has_ident(self, test_obj):
self.assertTill(self.ifmap_has_ident, obj=test_obj)
def assert_vnc_db_has_ident(self, test_obj):
self.assertTill(self.vnc_db_has_ident, obj=test_obj)
# end class ApiServerTestCase


Expand All @@ -93,30 +92,4 @@ def setUpClass(cls, extra_config_knobs=None, extra_mocks=None):
super(ApiServerRDBMSTestCase, cls).setUpClass(
db="rdbms", extra_config_knobs=extra_config_knobs,
extra_mocks=extra_mocks)
#end class ApiServerRDBMSTestCase


class ApiServerIrondTestCase(ApiServerTestCase):
@classmethod
def setUpClass(cls, extra_config_knobs=None, extra_mocks=None):
irond_config = [
('DEFAULTS', 'ifmap_server_ip', '127.0.0.1'),
('DEFAULTS', 'ifmap_health_check_interval', '3600'),
]
irond_mocks = [
(ifmap_client.client, '__init__', FakeIfmapClient.initialize),
(ifmap_client.client, 'call', FakeIfmapClient.call),
(ifmap_client.client, 'call_async_result',
FakeIfmapClient.call_async_result),
]
if extra_config_knobs:
extra_config_knobs.extend(irond_config)
else:
extra_config_knobs = irond_config
if extra_mocks:
extra_mocks.extend(irond_mocks)
else:
extra_mocks = irond_mocks
super(ApiServerIrondTestCase, cls).setUpClass(
extra_config_knobs=extra_config_knobs, extra_mocks=extra_mocks)

# end class ApiServerRDBMSTestCase

0 comments on commit 092b1e9

Please sign in to comment.