# Path: opennsa/error.py
# LOG_SYSTEM = 'error'
# NSI_ERROR_CODE_TABLE = {
#     '00100' : PayloadError,
#     '00101' : MissingParameterError,
#     '00200' : ConnectionError,
#     '00201' : InvalidTransitionError,
#     '00202' : ConnectionExistsError,
#     '00203' : ConnectionNonExistentError,
#     '00204' : ConnectionGoneError,
#     '00205' : ConnectionCreateError,
#     '00300' : SecurityError,
#     '00301' : AuthenticationFailure,
#     '00302' : UnauthorizedError,
#     '00400' : TopologyError,
#     '00401' : UnknownSTPError,                      # compat
#     '00402' : STPResolutionError,                   # compat
#     '00403' : NoPathFoundError,
#     '00404' : VLANInterchangeNotSupportedError,     # compat
#     '00500' : InternalServerError,
#     '00501' : InternalNRMError,
#     '00600' : ResourceUnavailableError,
#     '00601' : STPUnavailableError,                  # compat
#     '00602' : BandwidthUnavailableError,            # compat
#     '00700' : ServiceError,
#     '00701' : UnknownSTPError,
#     '00702' : STPResolutionError,
#     '00703' : VLANInterchangeNotSupportedError,
#     '00704' : STPUnavailableError,
#     '00705' : BandwidthUnavailableError             # compat
# }
# class CallbackTimeoutError(Exception):
# class NSIError(Exception):
# class UnknownNSIError(NSIError):
# class PayloadError(NSIError):
# class MissingParameterError(PayloadError):
# class UnsupportedParameter(PayloadError):
# class ConnectionError(NSIError):
# class InvalidTransitionError(ConnectionError):
# class ConnectionExistsError(ConnectionError):
# class ConnectionNonExistentError(ConnectionError):
# class ConnectionGoneError(ConnectionError):
# class ConnectionCreateError(ConnectionError):
# class SecurityError(NSIError):
# class AuthenticationFailure(SecurityError):
# class UnauthorizedError(SecurityError):
# class TopologyError(NSIError):
# class NoPathFoundError(NSIError):
# class InternalServerError(NSIError):
# class InternalNRMError(InternalServerError):
# class DownstreamNSAError(InternalServerError):
# class ResourceUnavailableError(NSIError):
# class ServiceError(NSIError): # only use this if nothing else applies
# class UnknownSTPError(ServiceError):
# class STPResolutionError(NSIError):
# class VLANInterchangeNotSupportedError(TopologyError):
# class STPUnavailableError(ServiceError, TopologyError): # need this to be a topology error internally
# class BandwidthUnavailableError(ServiceError): # NSI error name is CAPACITY_UNAVAILABLE
#     def __init__(self, message, nsa_id=None, connection_id=None, variables=None):
# def lookup(error_code):
# 
# Path: opennsa/backends/common/calendar.py
# class ReservationCalendar:
#     def __init__(self):
#     def _checkArgs(self, resource, start_time, end_time):
#     def addReservation(self, resource, start_time, end_time):
#     def removeReservation(self, resource, start_time, end_time):
#     def checkReservation(self, resource, start_time, end_time):
#     def _resourceOverlap(self, res1_start_time, res1_end_time, res2_start_time, res2_end_time):


import datetime
from twisted.trial import unittest
from opennsa import error
from opennsa.backends.common import calendar
        ds = datetime.datetime.utcnow() + datetime.timedelta(seconds=1)
        de = datetime.datetime.utcnow() + datetime.timedelta(seconds=3)
        self.c.checkReservation('r1', ds, de)
        self.c.addReservation('r1', ds, de)


    def testDoubleCheckAdd(self):

        ds1 = datetime.datetime.utcnow() + datetime.timedelta(seconds=1)
        de1 = datetime.datetime.utcnow() + datetime.timedelta(seconds=3)
        ds2 = datetime.datetime.utcnow() + datetime.timedelta(seconds=5)
        de2 = datetime.datetime.utcnow() + datetime.timedelta(seconds=7)

        self.c.checkReservation('r1', ds1, de1)
        self.c.addReservation('r1', ds1, de1)

        self.c.checkReservation('r1', ds2, de2)
        self.c.addReservation('r1', ds2, de2)


    def testSimpleConflict(self):

        ds1 = datetime.datetime.utcnow() + datetime.timedelta(seconds=1)
        de1 = datetime.datetime.utcnow() + datetime.timedelta(seconds=5)
        ds2 = datetime.datetime.utcnow() + datetime.timedelta(seconds=4)
        de2 = datetime.datetime.utcnow() + datetime.timedelta(seconds=7)

        self.c.checkReservation('r1', ds1, de1)
        self.c.addReservation('r1', ds1, de2)


# Path: opennsa/error.py
# LOG_SYSTEM = 'error'
# NSI_ERROR_CODE_TABLE = {
#     '00100' : PayloadError,
#     '00101' : MissingParameterError,
#     '00200' : ConnectionError,
#     '00201' : InvalidTransitionError,
#     '00202' : ConnectionExistsError,
#     '00203' : ConnectionNonExistentError,
#     '00204' : ConnectionGoneError,
#     '00205' : ConnectionCreateError,
#     '00300' : SecurityError,
#     '00301' : AuthenticationFailure,
#     '00302' : UnauthorizedError,
#     '00400' : TopologyError,
#     '00401' : UnknownSTPError,                      # compat
#     '00402' : STPResolutionError,                   # compat
#     '00403' : NoPathFoundError,
#     '00404' : VLANInterchangeNotSupportedError,     # compat
#     '00500' : InternalServerError,
#     '00501' : InternalNRMError,
#     '00600' : ResourceUnavailableError,
#     '00601' : STPUnavailableError,                  # compat
#     '00602' : BandwidthUnavailableError,            # compat
#     '00700' : ServiceError,
#     '00701' : UnknownSTPError,
#     '00702' : STPResolutionError,
#     '00703' : VLANInterchangeNotSupportedError,
#     '00704' : STPUnavailableError,
#     '00705' : BandwidthUnavailableError             # compat
# }
# class CallbackTimeoutError(Exception):
# class NSIError(Exception):
# class UnknownNSIError(NSIError):
# class PayloadError(NSIError):
# class MissingParameterError(PayloadError):
# class UnsupportedParameter(PayloadError):
# class ConnectionError(NSIError):
# class InvalidTransitionError(ConnectionError):
# class ConnectionExistsError(ConnectionError):
# class ConnectionNonExistentError(ConnectionError):
# class ConnectionGoneError(ConnectionError):
# class ConnectionCreateError(ConnectionError):
# class SecurityError(NSIError):
# class AuthenticationFailure(SecurityError):
# class UnauthorizedError(SecurityError):
# class TopologyError(NSIError):
# class NoPathFoundError(NSIError):
# class InternalServerError(NSIError):
# class InternalNRMError(InternalServerError):
# class DownstreamNSAError(InternalServerError):
# class ResourceUnavailableError(NSIError):
# class ServiceError(NSIError): # only use this if nothing else applies
# class UnknownSTPError(ServiceError):
# class STPResolutionError(NSIError):
# class VLANInterchangeNotSupportedError(TopologyError):
# class STPUnavailableError(ServiceError, TopologyError): # need this to be a topology error internally
# class BandwidthUnavailableError(ServiceError): # NSI error name is CAPACITY_UNAVAILABLE
#     def __init__(self, message, nsa_id=None, connection_id=None, variables=None):
# def lookup(error_code):
# 
# Path: opennsa/backends/common/calendar.py
# class ReservationCalendar:
#     def __init__(self):
#     def _checkArgs(self, resource, start_time, end_time):
#     def addReservation(self, resource, start_time, end_time):
#     def removeReservation(self, resource, start_time, end_time):
#     def checkReservation(self, resource, start_time, end_time):
#     def _resourceOverlap(self, res1_start_time, res1_end_time, res2_start_time, res2_end_time):


# Path: test/test_calendar.py
import datetime
from twisted.trial import unittest
from opennsa import error
from opennsa.backends.common import calendar

        ds = datetime.datetime.utcnow() + datetime.timedelta(seconds=1)
        de = datetime.datetime.utcnow() + datetime.timedelta(seconds=3)
        self.c.checkReservation('r1', ds, de)
        self.c.addReservation('r1', ds, de)


    def testDoubleCheckAdd(self):

        ds1 = datetime.datetime.utcnow() + datetime.timedelta(seconds=1)
        de1 = datetime.datetime.utcnow() + datetime.timedelta(seconds=3)
        ds2 = datetime.datetime.utcnow() + datetime.timedelta(seconds=5)
        de2 = datetime.datetime.utcnow() + datetime.timedelta(seconds=7)

        self.c.checkReservation('r1', ds1, de1)
        self.c.addReservation('r1', ds1, de1)

        self.c.checkReservation('r1', ds2, de2)
        self.c.addReservation('r1', ds2, de2)


    def testSimpleConflict(self):

        ds1 = datetime.datetime.utcnow() + datetime.timedelta(seconds=1)
        de1 = datetime.datetime.utcnow() + datetime.timedelta(seconds=5)
        ds2 = datetime.datetime.utcnow() + datetime.timedelta(seconds=4)
        de2 = datetime.datetime.utcnow() + datetime.timedelta(seconds=7)

        self.c.checkReservation('r1', ds1, de1)
        self.c.addReservation('r1', ds1, de2)


        self.failUnlessRaises(error.STPUnavailableError, self.c.checkReservation, 'r1', ds2, de2)