def test_delete_bnp_phys_switch_by_name(self):
     """Test delete_bnp_phys_switch_by_name method."""
     sw_dict = self._get_bnp_phys_switch_dict()
     db.add_bnp_phys_switch(self.ctx, sw_dict)
     switch = db.get_bnp_phys_switch_by_name(self.ctx, sw_dict['name'])
     db.delete_bnp_phys_switch_by_name(self.ctx, switch[0]['name'])
     count = self.ctx.session.query(models.BNPPhysicalSwitch).count()
     self.assertEqual(0, count)
 def test_update_bnp_phys_switch_status(self):
     sw_dict = self._get_bnp_phys_switch_dict()
     db.add_bnp_phys_switch(self.ctx, sw_dict)
     switches = db.get_all_bnp_phys_switches(self.ctx)
     db.update_bnp_phys_switch_status(self.ctx,
                                      switches[0]['id'],
                                      "disable")
     sw_updt = self.ctx.session.query(models.BNPPhysicalSwitch).all()
     self.assertNotEqual(sw_updt[0]['status'], "disable")
 def test_get_bnp_phys_switch(self):
     """Test get_bnp_phys_switch method."""
     sw_dict = self._get_bnp_phys_switch_dict()
     db.add_bnp_phys_switch(self.ctx, sw_dict)
     sw_mac = db.get_bnp_phys_switch_by_mac(self.ctx,
                                            sw_dict['mac_address'])
     sw_ip = db.get_bnp_phys_switch_by_ip(self.ctx, sw_dict['ip_address'])
     sw = db.get_bnp_phys_switch(self.ctx, sw_mac['id'])
     self.assertEqual(sw['id'], sw_mac['id'])
     self.assertEqual(sw['id'], sw_ip['id'])
 def test_update_bnp_phys_switch_access_params(self):
     """Tests update_bnp_phys_switch_access_params method."""
     sw_dict = self._get_bnp_phys_switch_dict()
     param_dict = self._get_bnp_access_param_dict()
     db.add_bnp_phys_switch(self.ctx, sw_dict)
     switches = db.get_all_bnp_phys_switches(self.ctx)
     db.update_bnp_phys_switch_access_params(self.ctx,
                                             switches[0]['id'],
                                             param_dict)
     sw_updt = self.ctx.session.query(models.BNPPhysicalSwitch).all()
     self.assertNotEqual(sw_updt[0]['access_protocol'], "snmpv3")
 def test_list_swicth_port(self):
     self.data = {'vendor': "hpe",
                  'name': "switch1",
                  'family': "hp5900",
                  'management_protocol': "snmpv1",
                  'port_provisioning': "ENABLED",
                  'mac_address': "44:31:92:61:89:d2",
                  'credentials': "cred1",
                  'ip_address': "105.0.1.109",
                  'validation_result': "success"}
     self.mapping_dict = {'neutron_port_id': "24",
                          'switch_port_name': "TenGigabitEthernet",
                          'lag_id': None,
                          'access_type': "access",
                          'segmentation_id': 3,
                          'bind_status': 0,
                          'ifindex': "8"}
     sw = db.add_bnp_phys_switch(self.ctx, self.data)
     self.mapping_dict['switch_id'] = sw['id']
     db.add_bnp_switch_port_map(self.ctx, self.mapping_dict)
     db.add_bnp_neutron_port(self.ctx, self.mapping_dict)
     list_req = self.new_list_request('bnp-switch-ports')
     result = self.bnp_wsgi_controller.index(list_req)
     result = result.pop('bnp_switch_ports')
     self.assertEqual(1, len(result))
 def test_list_swicth_port(self):
     self.data = {
         'vendor': "hpe",
         'name': "switch1",
         'family': "hp5900",
         'management_protocol': "snmpv1",
         'port_provisioning': "ENABLED",
         'mac_address': "44:31:92:61:89:d2",
         'credentials': "cred1",
         'ip_address': "105.0.1.109",
         'validation_result': "success"
     }
     self.mapping_dict = {
         'neutron_port_id': "24",
         'switch_port_name': "TenGigabitEthernet",
         'lag_id': None,
         'access_type': "access",
         'segmentation_id': 3,
         'bind_status': 0,
         'ifindex': "8"
     }
     sw = db.add_bnp_phys_switch(self.ctx, self.data)
     self.mapping_dict['switch_id'] = sw['id']
     db.add_bnp_switch_port_map(self.ctx, self.mapping_dict)
     db.add_bnp_neutron_port(self.ctx, self.mapping_dict)
     list_req = self.new_list_request('bnp-switch-ports')
     result = self.bnp_wsgi_controller.index(list_req)
     result = result.pop('bnp_switch_ports')
     self.assertEqual(1, len(result))
 def test_get_all_bnp_switch_port_maps(self):
     """Test get_all_bnp_switch_port_maps method."""
     sw_dict = self._get_bnp_phys_switch_dict()
     phy_switch = db.add_bnp_phys_switch(self.ctx, sw_dict)
     port_dict = self._get_bnp_neutron_port_dict()
     db.add_bnp_neutron_port(self.ctx, port_dict)
     port_map = self._get_bnp_switch_port_map_dict()
     port_map['switch_id'] = phy_switch['id']
     db.add_bnp_switch_port_map(self.ctx, port_map)
     ports = db.get_all_bnp_switch_port_maps(self.ctx)
     self.assertEqual(ports[0][0], port_map['neutron_port_id'])
 def create(self, request, **kwargs):
     context = request.context
     self._check_admin(context)
     body = validators.validate_request(request)
     key_list = ['name', 'ip_address', 'vendor',
                 'disc_proto', 'disc_creds',
                 'prov_proto', 'prov_creds']
     keys = body.keys()
     for key in key_list:
         if key not in keys:
             raise webob.exc.HTTPBadRequest(
                 _("Key %s not found in request body") % key)
     validators.validate_switch_attributes(keys, key_list)
     if body['vendor'] not in const.SUPPORTED_VENDORS:
         raise webob.exc.HTTPBadRequest(
             _("Switch with vendor %s is not supported") %
             body['vendor'])
     ip_address = body['ip_address']
     bnp_switch = db.get_bnp_phys_switch_by_ip(context,
                                               ip_address)
     if bnp_switch:
         raise webob.exc.HTTPConflict(
             _("Switch with ip_address %s is already present") %
             ip_address)
     access_parameters = self._get_access_param(context, body['disc_proto'],
                                                body['disc_creds'])
     for key, value in access_parameters.iteritems():
         body[key] = value
     bnp_switch = self._discover_switch(body)
     if bnp_switch.get('mac_address'):
         body['mac_address'] = bnp_switch.get('mac_address')
         body['port_prov'] = const.SWITCH_STATUS['enable']
     else:
         body['port_prov'] = const.SWITCH_STATUS['create']
     if 'family' not in body:
         body['family'] = None
     db_switch = db.add_bnp_phys_switch(context, body)
     if bnp_switch.get('ports'):
         self._add_physical_port(context, db_switch.get('id'),
                                 bnp_switch.get('ports'))
     return {const.BNP_SWITCH_RESOURCE_NAME: dict(db_switch)}
 def create(self, request):
     context = request.context
     self._check_admin(context)
     body = validators.validate_request(request)
     key_list = ['ip_address', 'vendor',
                 'access_protocol', 'access_parameters']
     keys = body.keys()
     for key in key_list:
         if key not in keys:
             raise webob.exc.HTTPBadRequest(
                 _("Key %s not found in request body") % key)
     if body['vendor'] not in const.SUPPORTED_VENDORS:
         raise webob.exc.HTTPBadRequest(
             _("Switch with vendor %s is not supported") %
             body['vendor'])
     ip_address = body['ip_address']
     bnp_switch = db.get_bnp_phys_switch_by_ip(context,
                                               ip_address)
     if bnp_switch:
         raise webob.exc.HTTPConflict(
             _("Switch with ip_address %s is already present") %
             ip_address)
     validators.validate_access_parameters(body)
     access_parameters = body.pop("access_parameters")
     switch_dict = self._create_switch_dict()
     for key, value in access_parameters.iteritems():
         body[key] = value
     switch = self._update_dict(body, switch_dict)
     bnp_switch = self._discover_switch(switch)
     if bnp_switch.get('mac_address'):
         switch['mac_address'] = bnp_switch.get('mac_address')
         switch['status'] = const.SWITCH_STATUS['enable']
     else:
         switch['status'] = const.SWITCH_STATUS['create']
     db_switch = db.add_bnp_phys_switch(context, switch)
     if bnp_switch.get('ports'):
         self._add_physical_port(context, db_switch.get('id'),
                                 bnp_switch.get('ports'))
     return dict(db_switch)
 def create(self, request, **kwargs):
     context = request.context
     self._check_admin(context)
     body = validators.validate_request(request)
     key_list = ['name', 'ip_address', 'vendor',
                 'management_protocol', 'credentials',
                 'mac_address']
     keys = body.keys()
     for key in key_list:
         if key not in keys:
             raise webob.exc.HTTPBadRequest(
                 _("Key %s not found in request body") % key)
     key_list.append('family')
     validators.validate_attributes(keys, key_list)
     ip_address = body['ip_address']
     if const.FAMILY not in body:
         body['family'] = ''
     bnp_switch = db.get_bnp_phys_switch_by_ip(context,
                                               ip_address)
     if bnp_switch:
         raise webob.exc.HTTPConflict(
             _("Switch with ip_address %s is already present") %
             ip_address)
     filters = {'mac_address': body['mac_address']}
     switch_exists = db.get_if_bnp_phy_switch_exists(context, **filters)
     if switch_exists:
         raise webob.exc.HTTPConflict(
             _("Switch with mac_address %s is already present") %
             body['mac_address'])
     access_parameters = self._get_access_param(context,
                                                body['management_protocol'],
                                                body['credentials'])
     credentials = body['credentials']
     body['port_provisioning'] = const.PORT_PROVISIONING_STATUS['enable']
     result = self.validate_protocol(access_parameters, credentials, body)
     body['validation_result'] = result
     db_switch = db.add_bnp_phys_switch(context, body)
     return {const.BNP_SWITCH_RESOURCE_NAME: dict(db_switch)}
 def create(self, request, **kwargs):
     context = request.context
     self._check_admin(context)
     body = validators.validate_request(request)
     key_list = ['name', 'ip_address', 'vendor',
                 'management_protocol', 'credentials',
                 'mac_address']
     keys = body.keys()
     for key in key_list:
         if key not in keys:
             raise webob.exc.HTTPBadRequest(
                 _("Key %s not found in request body") % key)
     key_list.append('family')
     validators.validate_attributes(keys, key_list)
     ip_address = body['ip_address']
     if const.FAMILY not in body:
         body['family'] = ''
     bnp_switch = db.get_bnp_phys_switch_by_ip(context,
                                               ip_address)
     if bnp_switch:
         raise webob.exc.HTTPConflict(
             _("Switch with ip_address %s is already present") %
             ip_address)
     filters = {'mac_address': body['mac_address']}
     switch_exists = db.get_if_bnp_phy_switch_exists(context, **filters)
     if switch_exists:
         raise webob.exc.HTTPConflict(
             _("Switch with mac_address %s is already present") %
             body['mac_address'])
     access_parameters = self._get_access_param(context,
                                                body['management_protocol'],
                                                body['credentials'])
     credentials = body['credentials']
     body['port_provisioning'] = const.SWITCH_STATUS['enable']
     result = self.validate_protocol(access_parameters, credentials, body)
     body['validation_result'] = result
     db_switch = db.add_bnp_phys_switch(context, body)
     return {const.BNP_SWITCH_RESOURCE_NAME: dict(db_switch)}
 def test_get_all_bnp_phys_switches(self):
     """Test get_all__bnp_phys_switches method."""
     sw_dict = self._get_bnp_phys_switch_dict()
     db.add_bnp_phys_switch(self.ctx, sw_dict)
     switches = db.get_all_bnp_phys_switches(self.ctx)
     self.assertEqual(1, len(switches))
 def test_add_bnp_phys_switch(self):
     """Test add_bnp_phys_switch method."""
     sw_dict = self._get_bnp_phys_switch_dict()
     db.add_bnp_phys_switch(self.ctx, sw_dict)
     count = self.ctx.session.query(models.BNPPhysicalSwitch).count()
     self.assertEqual(1, count)