NSXv - dispose unused code
Delete some NAT methods and related UTs, which weren't in use. Change-Id: Id403a5447f9c92be50dbf2f22d4c1d80a75ec28c
This commit is contained in:
parent
e04afa87bf
commit
beb61a55ca
@ -690,128 +690,6 @@ class EdgeApplianceDriver(object):
|
||||
e.response)
|
||||
raise e
|
||||
|
||||
def _create_nat_rule(self, task):
|
||||
# TODO(fank): use POST for optimization
|
||||
# return rule_id for future reference
|
||||
rule = task.userdata['rule']
|
||||
LOG.debug("VCNS: start creating nat rules: %s", rule)
|
||||
edge_id = task.userdata['edge_id']
|
||||
nat = self.get_nat_config(edge_id)
|
||||
location = task.userdata['location']
|
||||
|
||||
del nat['version']
|
||||
|
||||
if location is None or location == constants.APPEND:
|
||||
nat['rules']['natRulesDtos'].append(rule)
|
||||
else:
|
||||
nat['rules']['natRulesDtos'].insert(location, rule)
|
||||
|
||||
try:
|
||||
self.vcns.update_nat_config(edge_id, nat)
|
||||
status = task_constants.TaskStatus.COMPLETED
|
||||
except exceptions.VcnsApiException as e:
|
||||
LOG.exception(_LE("VCNS: Failed to create snat rule:\n%s"),
|
||||
e.response)
|
||||
status = task_constants.TaskStatus.ERROR
|
||||
|
||||
return status
|
||||
|
||||
def create_snat_rule(self, router_id, edge_id, src, translated,
|
||||
jobdata=None, location=None):
|
||||
LOG.debug("VCNS: create snat rule %(src)s/%(translated)s", {
|
||||
'src': src, 'translated': translated})
|
||||
snat_rule = self._assemble_nat_rule("snat", src, translated)
|
||||
userdata = {
|
||||
'router_id': router_id,
|
||||
'edge_id': edge_id,
|
||||
'rule': snat_rule,
|
||||
'location': location,
|
||||
'jobdata': jobdata
|
||||
}
|
||||
task_name = "create-snat-%s-%s-%s" % (edge_id, src, translated)
|
||||
task = tasks.Task(task_name, router_id, self._create_nat_rule,
|
||||
userdata=userdata)
|
||||
task.add_result_monitor(self.callbacks.snat_create_result)
|
||||
self.task_manager.add(task)
|
||||
return task
|
||||
|
||||
def _delete_nat_rule(self, task):
|
||||
# TODO(fank): pass in rule_id for optimization
|
||||
# handle routes update for optimization
|
||||
edge_id = task.userdata['edge_id']
|
||||
address = task.userdata['address']
|
||||
addrtype = task.userdata['addrtype']
|
||||
LOG.debug("VCNS: start deleting %(type)s rules: %(addr)s", {
|
||||
'type': addrtype, 'addr': address})
|
||||
nat = self.get_nat_config(edge_id)
|
||||
del nat['version']
|
||||
status = task_constants.TaskStatus.COMPLETED
|
||||
for nat_rule in nat['rules']['natRulesDtos']:
|
||||
if nat_rule[addrtype] == address:
|
||||
rule_id = nat_rule['ruleId']
|
||||
try:
|
||||
self.vcns.delete_nat_rule(edge_id, rule_id)
|
||||
except exceptions.VcnsApiException as e:
|
||||
LOG.exception(_LE("VCNS: Failed to delete snat rule:\n"
|
||||
"%s"), e.response)
|
||||
status = task_constants.TaskStatus.ERROR
|
||||
|
||||
return status
|
||||
|
||||
def delete_snat_rule(self, router_id, edge_id, src, jobdata=None):
|
||||
LOG.debug("VCNS: delete snat rule %s", src)
|
||||
userdata = {
|
||||
'edge_id': edge_id,
|
||||
'address': src,
|
||||
'addrtype': 'originalAddress',
|
||||
'jobdata': jobdata
|
||||
}
|
||||
task_name = "delete-snat-%s-%s" % (edge_id, src)
|
||||
task = tasks.Task(task_name, router_id, self._delete_nat_rule,
|
||||
userdata=userdata)
|
||||
task.add_result_monitor(self.callbacks.snat_delete_result)
|
||||
self.task_manager.add(task)
|
||||
return task
|
||||
|
||||
def create_dnat_rule(self, router_id, edge_id, dst, translated,
|
||||
jobdata=None, location=None):
|
||||
# TODO(fank): use POST for optimization
|
||||
# return rule_id for future reference
|
||||
LOG.debug("VCNS: create dnat rule %(dst)s/%(translated)s", {
|
||||
'dst': dst, 'translated': translated})
|
||||
dnat_rule = self._assemble_nat_rule(
|
||||
"dnat", dst, translated)
|
||||
userdata = {
|
||||
'router_id': router_id,
|
||||
'edge_id': edge_id,
|
||||
'rule': dnat_rule,
|
||||
'location': location,
|
||||
'jobdata': jobdata
|
||||
}
|
||||
task_name = "create-dnat-%s-%s-%s" % (edge_id, dst, translated)
|
||||
task = tasks.Task(task_name, router_id, self._create_nat_rule,
|
||||
userdata=userdata)
|
||||
task.add_result_monitor(self.callbacks.dnat_create_result)
|
||||
self.task_manager.add(task)
|
||||
return task
|
||||
|
||||
def delete_dnat_rule(self, router_id, edge_id, translated,
|
||||
jobdata=None):
|
||||
# TODO(fank): pass in rule_id for optimization
|
||||
LOG.debug("VCNS: delete dnat rule %s", translated)
|
||||
userdata = {
|
||||
'edge_id': edge_id,
|
||||
'address': translated,
|
||||
'addrtype': 'translatedAddress',
|
||||
'jobdata': jobdata
|
||||
}
|
||||
task_name = "delete-dnat-%s-%s" % (edge_id, translated)
|
||||
task = tasks.Task(task_name, router_id, self._delete_nat_rule,
|
||||
userdata=userdata)
|
||||
task.add_result_monitor(self.callbacks.dnat_delete_result)
|
||||
self.task_manager.add(task)
|
||||
return task
|
||||
|
||||
def _update_nat_rule(self, task):
|
||||
# TODO(fank): use POST for optimization
|
||||
# return rule_id for future reference
|
||||
@ -881,29 +759,6 @@ class EdgeApplianceDriver(object):
|
||||
self.task_manager.add(task)
|
||||
return task
|
||||
|
||||
def update_dnat_rules(self, edge_id, dnat_rules):
|
||||
edge_nat_rules = []
|
||||
for rule in dnat_rules:
|
||||
edge_nat_rules.append(
|
||||
self._assemble_nat_rule(
|
||||
'dnat',
|
||||
rule['dst'],
|
||||
rule['translated'],
|
||||
vnic_index=rule['vnic_index'],
|
||||
enabled=True,
|
||||
protocol=rule['protocol'],
|
||||
original_port=rule['original_port'],
|
||||
translated_port=rule['translated_port']))
|
||||
|
||||
nat = {
|
||||
'featureType': 'nat',
|
||||
'rules': {
|
||||
'natRulesDtos': edge_nat_rules
|
||||
}
|
||||
}
|
||||
|
||||
self.vcns.update_nat_config(edge_id, nat)
|
||||
|
||||
def _update_routes(self, task):
|
||||
edge_id = task.userdata['edge_id']
|
||||
if (task != self.updated_task['route'][edge_id] and
|
||||
|
@ -2230,22 +2230,6 @@ def update_nat_rules(nsxv_manager, context, router_id, snat, dnat):
|
||||
LOG.warning(_LW("Bindings do not exists for %s"), router_id)
|
||||
|
||||
|
||||
def update_dnat_rules(nsxv_manager, context, router_id, dnat_rules):
|
||||
rtr_binding = nsxv_db.get_nsxv_router_binding(context.session, router_id)
|
||||
edge_id = rtr_binding['edge_id']
|
||||
|
||||
for dnat_rule in dnat_rules:
|
||||
vnic_binding = nsxv_db.get_edge_vnic_binding(
|
||||
context.session,
|
||||
edge_id,
|
||||
dnat_rule['network_id'])
|
||||
|
||||
vnic_index = vnic_binding['vnic_index']
|
||||
dnat_rule['vnic_index'] = vnic_index
|
||||
|
||||
nsxv_manager.update_dnat_rules(edge_id, dnat_rules)
|
||||
|
||||
|
||||
def clear_nat_rules(nsxv_manager, context, router_id):
|
||||
update_nat_rules(nsxv_manager, context, router_id, [], [])
|
||||
|
||||
@ -2410,18 +2394,6 @@ class NsxVCallbacks(object):
|
||||
def interface_update_result(self, task):
|
||||
LOG.debug("interface_update_result %d", task.status)
|
||||
|
||||
def snat_create_result(self, task):
|
||||
LOG.debug("snat_create_result %d", task.status)
|
||||
|
||||
def snat_delete_result(self, task):
|
||||
LOG.debug("snat_delete_result %d", task.status)
|
||||
|
||||
def dnat_create_result(self, task):
|
||||
LOG.debug("dnat_create_result %d", task.status)
|
||||
|
||||
def dnat_delete_result(self, task):
|
||||
LOG.debug("dnat_delete_result %d", task.status)
|
||||
|
||||
def routes_update_result(self, task):
|
||||
LOG.debug("routes_update_result %d", task.status)
|
||||
|
||||
|
@ -366,22 +366,6 @@ class VcnsDriverTestCase(base.BaseTestCase):
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['edge_delete_result'] = True
|
||||
|
||||
def snat_create_result(self, task):
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['snat_create_result'] = True
|
||||
|
||||
def snat_delete_result(self, task):
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['snat_delete_result'] = True
|
||||
|
||||
def dnat_create_result(self, task):
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['dnat_create_result'] = True
|
||||
|
||||
def dnat_delete_result(self, task):
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['dnat_delete_result'] = True
|
||||
|
||||
def nat_update_result(self, task):
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['nat_update_result'] = True
|
||||
@ -439,76 +423,6 @@ class VcnsDriverTestCase(base.BaseTestCase):
|
||||
break
|
||||
self.assertTrue(found)
|
||||
|
||||
def _create_nat_rule(self, edge_id, action, org, translated):
|
||||
jobdata = {}
|
||||
if action == 'snat':
|
||||
task = self.vcns_driver.create_snat_rule(
|
||||
'router-id', edge_id, org, translated, jobdata=jobdata)
|
||||
key = 'snat_create_result'
|
||||
else:
|
||||
task = self.vcns_driver.create_dnat_rule(
|
||||
'router-id', edge_id, org, translated, jobdata=jobdata)
|
||||
key = 'dnat_create_result'
|
||||
task.wait(ts_const.TaskState.RESULT)
|
||||
self.assertTrue(jobdata.get(key))
|
||||
|
||||
def _delete_nat_rule(self, edge_id, action, addr):
|
||||
jobdata = {}
|
||||
if action == 'snat':
|
||||
task = self.vcns_driver.delete_snat_rule(
|
||||
'router-id', edge_id, addr, jobdata=jobdata)
|
||||
key = 'snat_delete_result'
|
||||
else:
|
||||
task = self.vcns_driver.delete_dnat_rule(
|
||||
'router-id', edge_id, addr, jobdata=jobdata)
|
||||
key = 'dnat_delete_result'
|
||||
task.wait(ts_const.TaskState.RESULT)
|
||||
self.assertTrue(jobdata.get(key))
|
||||
|
||||
def _test_create_nat_rule(self, action):
|
||||
self._deploy_edge()
|
||||
addr = '192.168.1.1'
|
||||
translated = '10.0.0.1'
|
||||
self._create_nat_rule(self.edge_id, action, addr, translated)
|
||||
|
||||
natcfg = self.vcns_driver.get_nat_config(self.edge_id)
|
||||
for rule in natcfg['rules']['natRulesDtos']:
|
||||
if (rule['originalAddress'] == addr and
|
||||
rule['translatedAddress'] == translated and
|
||||
rule['action'] == action):
|
||||
break
|
||||
else:
|
||||
self.assertTrue(False)
|
||||
|
||||
def _test_delete_nat_rule(self, action):
|
||||
self._deploy_edge()
|
||||
addr = '192.168.1.1'
|
||||
translated = '10.0.0.1'
|
||||
self._create_nat_rule(self.edge_id, action, addr, translated)
|
||||
if action == 'snat':
|
||||
self._delete_nat_rule(self.edge_id, action, addr)
|
||||
else:
|
||||
self._delete_nat_rule(self.edge_id, action, translated)
|
||||
natcfg = self.vcns_driver.get_nat_config(self.edge_id)
|
||||
for rule in natcfg['rules']['natRulesDtos']:
|
||||
if (rule['originalAddress'] == addr and
|
||||
rule['translatedAddress'] == translated and
|
||||
rule['action'] == action):
|
||||
self.assertTrue(False)
|
||||
break
|
||||
|
||||
def test_create_snat_rule(self):
|
||||
self._test_create_nat_rule('snat')
|
||||
|
||||
def test_delete_snat_rule(self):
|
||||
self._test_delete_nat_rule('snat')
|
||||
|
||||
def test_create_dnat_rule(self):
|
||||
self._test_create_nat_rule('dnat')
|
||||
|
||||
def test_delete_dnat_rule(self):
|
||||
self._test_delete_nat_rule('dnat')
|
||||
|
||||
def test_update_nat_rules(self):
|
||||
self._deploy_edge()
|
||||
jobdata = {}
|
||||
|
Loading…
Reference in New Issue
Block a user