Ejemplo n.º 1
0
 def test_is_free_unique_id(self):
     result = unique_ids.is_free_unique_id(self.id_collection,
                                           'TEST-000001')
     self.assertTrue(result)
     unique_ids.register_unique_id(self.id_collection, 'TEST-000001')
     result = unique_ids.is_free_unique_id(self.id_collection,
                                           'TEST-000001')
     self.assertFalse(result)
Ejemplo n.º 2
0
 def test_register_used_id(self):
     result = unique_ids.register_unique_id(self.id_collection,
                                            'TEST-000001')
     self.assertTrue(result)
     try:
         sid = transaction.savepoint()
         unique_ids.register_unique_id(self.id_collection, 'TEST-000001')
         transaction.savepoint_commit(sid)
     except IntegrityError as e:
         transaction.savepoint_rollback(sid)
         self.assertIsInstance(e, IntegrityError)
Ejemplo n.º 3
0
 def test_register_reserved_id(self):
     unique_ids.bulk_reserve_id_range(1, 99, self.id_generator,
                                      self.id_collection, 'Reserve message',
                                      self.user)
     result = unique_ids.register_unique_id(self.id_collection,
                                            'TEST-000001')
     self.assertTrue(result)
Ejemplo n.º 4
0
 def test_helper_functions_basics(self):
     new_id = self.id_generator.get_id()
     return_value = unique_ids.register_unique_id(self.id_collection,
                                                  new_id)
     self.assertEqual(return_value, True)
     next_id = self.id_generator.next_id
     new_id = unique_ids.get_collection_unique_id(self.id_generator,
                                                  self.id_collection)
     self.assertEqual(new_id, next_id)
Ejemplo n.º 5
0
 def test_register_unreserved_id(self):
     result = unique_ids.register_unique_id(self.id_collection,
                                            'TEST-000001')
     self.assertTrue(result)
Ejemplo n.º 6
0
 def obj_create(self, bundle, **kwargs):
     bundle.data.update(self._initial_form_data(bundle))
     try:
         if unique_ids.is_free_unique_id(NordunetUniqueId,
                                         bundle.data['node_name']):
             bundle.data['name'] = bundle.data['node_name']
         else:
             raise_conflict_error('Service ID (%s) is already in use.' %
                                  bundle.data['node_name'])
     except KeyError as e:
         raise_not_acceptable_error('%s is missing.' % e)
     form = forms.NewL2vpnServiceForm(bundle.data)
     if form.is_valid():
         bundle.data.update({
             'node_name':
             form.cleaned_data['name'],
             'creator':
             '/api/%s/user/%d/' %
             (self._meta.api_name, bundle.request.user.pk),
             'modifier':
             '/api/%s/user/%d/' %
             (self._meta.api_name, bundle.request.user.pk)
         })
         node_data = bundle.data.get('node', {})
         node_data.update({
             'service_type':
             form.cleaned_data['service_type'],
             'service_class':
             form.cleaned_data['service_class'],
             'ncs_service_name':
             form.cleaned_data['ncs_service_name'],
             'vpn_type':
             form.cleaned_data['vpn_type'],
             'vlan':
             form.cleaned_data['vlan'],
             'vrf_target':
             form.cleaned_data['vrf_target'],
             'route_distinguisher':
             form.cleaned_data['route_distinguisher'],
             'operational_state':
             form.cleaned_data['operational_state'],
             'description':
             form.cleaned_data['description'],
         })
         bundle.data['node'] = node_data
         del bundle.data['name']
         # Ensure that we have all the data needed to create the L2VPN service
         end_point_nodes = self.get_end_point_nodes(bundle)
         # Create the new service
         bundle = super(ServiceL2VPNResource,
                        self).obj_create(bundle, **kwargs)
         unique_ids.register_unique_id(NordunetUniqueId,
                                       bundle.data['node_name'])
         # Depend the created service on provided end points
         node = bundle.obj.get_node()
         for end_point in end_point_nodes:
             helpers.set_depends_on(bundle.request.user, node,
                                    end_point.handle_id)
         return self.hydrate_node(bundle)
     else:
         raise_not_acceptable_error([
             "%s is missing or incorrect." % key
             for key in form.errors.keys()
         ])