def test_config(self):
     reset_last_config_state()
     # Install the config handler
     field_list = ['internal', 'min', 'mac']
     add_config_handler({RestTestModel: field_list}, ConfigHandlerTest.config_handler)
     
     # Check that config handler is triggered on an insert
     ConfigHandlerTest.reset_config_handler()
     test = RestTestModel(**self.TEST_DATA)
     test.save()
     self.check_config_handler('INSERT', None, test, None)
     
     # Check that config handler is triggered on an update
     ConfigHandlerTest.reset_config_handler()
     expected_old = RestTestModel.objects.get(pk='foobar')
     test.internal = 'check'
     test.min = 125
     test.save()
     self.check_config_handler('UPDATE', expected_old, test, {'internal': 'check', 'min': 125})
     
     # Check that config handler is not triggered on an update to a field that
     # it's not configured to care about
     ConfigHandlerTest.reset_config_handler()
     test.max = 500
     test.save()
     self.check_config_handler(None, None, None, None)
     
     # Check that config handler is triggered on a delete
     ConfigHandlerTest.reset_config_handler()
     test.delete()
     # delete() clears the pk which messes up the instance
     # comparison logic in check_config_handler, so we hack
     # it back to the value it had before the delete
     test.name = 'foobar'    
     self.check_config_handler('DELETE', test, None, None)
Example #2
0
    def test_config(self):
        reset_last_config_state()
        # Install the config handler
        field_list = ['internal', 'min', 'mac']
        add_config_handler({RestTestModel: field_list},
                           ConfigHandlerTest.config_handler)

        # Check that config handler is triggered on an insert
        ConfigHandlerTest.reset_config_handler()
        test = RestTestModel(**self.TEST_DATA)
        test.save()
        self.check_config_handler('INSERT', None, test, None)

        # Check that config handler is triggered on an update
        ConfigHandlerTest.reset_config_handler()
        expected_old = RestTestModel.objects.get(pk='foobar')
        test.internal = 'check'
        test.min = 125
        test.save()
        self.check_config_handler('UPDATE', expected_old, test, {
            'internal': 'check',
            'min': 125
        })

        # Check that config handler is not triggered on an update to a field that
        # it's not configured to care about
        ConfigHandlerTest.reset_config_handler()
        test.max = 500
        test.save()
        self.check_config_handler(None, None, None, None)

        # Check that config handler is triggered on a delete
        ConfigHandlerTest.reset_config_handler()
        test.delete()
        # delete() clears the pk which messes up the instance
        # comparison logic in check_config_handler, so we hack
        # it back to the value it had before the delete
        test.name = 'foobar'
        self.check_config_handler('DELETE', test, None, None)
def init_config():
    # 
    # Associate the config handlers with specific callout for each of the fields
    #  Keep in mind that these are the django names, NOT the rest api names,
    #
    disabled_by_shell_variable = os.environ.get('SDNCON_CONFIG_HANDLERS_DISABLED', False)
    disabled_by_file = os.path.exists("%s/sdncon_config_handlers_disabled" % sdncon.SDN_ROOT)
    if not disabled_by_shell_variable and not disabled_by_file:
        add_config_handler({Controller: ['ntp_server']}, ntp_config_handler)
        add_config_handler({Controller: ['time_zone']}, tz_config_handler)
        add_config_handler(
            {
                Controller: ['domain_lookups_enabled', 'domain_name', 'default_gateway'],
                ControllerDomainNameServer: None,
                ControllerInterface: ['ip', 'netmask', 'mode'],
            }, network_config_handler)
        add_config_handler({ControllerAlias: ['alias']}, controller_alias_config_handler)
        add_config_handler({Controller: ['logging_enabled', 'logging_server', 'logging_level']}, logging_server_config_handler)
        add_config_handler({Feature: ['netvirt_feature']}, netvirt_feature_config_handler)
        add_config_handler({FirewallRule: None}, firewall_entry_handler)
        add_config_handler({GlobalConfig: ['cluster_number']}, vrrp_virtual_router_id_config_handle)
        add_config_handler({ TacacsPlusConfig: ["tacacs_plus_authn", "tacacs_plus_authz", "tacacs_plus_acct",
                                                "local_authn", "local_authz",
                                                "timeout", "key",],
                             TacacsPlusHost: ['ip', 'key'],
                             },
                           tacacs_plus_config_handler)
        add_config_handler({SnmpServerConfig: ['server_enable', 'community', 'location', 'contact']}, snmp_server_config_handler)
        add_config_handler({ImageDropUser: ['images_user_ssh_key']}, images_user_ssh_key_config_handler)
    else:
        add_config_handler(
            {
                Controller: ['domain_lookups_enabled', 'domain_name', 'default_gateway'],
                ControllerDomainNameServer: None,
                ControllerInterface: ['ip', 'netmask', 'mode'],
                ControllerAlias: ['alias'],
                FirewallRule: None,
                Feature: None,
                GlobalConfig: ['ha-enabled', 'cluster-number'],
            }, test_config_handler)