Ejemplo n.º 1
0
    def test_cfn_delete_inactive_stack(self, get_stack_name_function,
                                       get_first_public_elb_function,
                                       get_zone_id_function,
                                       get_legacy_name_function,
                                       get_zone_name_function,
                                       get_config_function,
                                       get_connection_function,
                                       isactive_function,
                                       get_env_tag_function):
        '''
        if tag is "active", delete only active dns records(TXT and Alias)
        NB this method didn't test ssl deleting
        Args:
            get_stack_name_function:
            get_first_public_elb_function:
            get_zone_id_function:
            get_legacy_name_function:
            get_zone_name_function:
            get_config_function:
            get_connection_function:
            isactive_function: mock env.tag to be inactive
            get_env_tag_function: mock to get env.tag

        Returns:

        '''
        get_connection_function.side_effect = self.connection_side_effect
        basic_config_mock = yaml.load(set_up_basic_config())
        get_config_function.return_value = config.ConfigParser(
            basic_config_mock, "unittest_stack_name", "dev", "test")
        # tail_function.side_effect = self.tail_logs
        ret = fab_tasks.cfn_delete(force=True)
        self.assertTrue(ret)
Ejemplo n.º 2
0
    def test_cfn_delete_active_records(self, get_stack_name_function,
                                       get_first_public_elb_function,
                                       get_zone_id_function,
                                       get_legacy_name_function,
                                       get_zone_name_function,
                                       get_config_function,
                                       get_connection_function,
                                       isactive_function):
        '''
        Delete active dns records
        Do not delete stack
        Args:
            get_stack_name_function:
            get_first_public_elb_function:
            get_zone_id_function:
            get_legacy_name_function:
            get_zone_name_function:
            get_config_function:
            get_connection_function:
            isactive_function: to mock env.tag to be active

        Returns:

        '''
        get_connection_function.side_effect = self.connection_side_effect
        basic_config_mock = yaml.load(set_up_basic_config())
        get_config_function.return_value = config.ConfigParser(
            basic_config_mock, "unittest_stack_name", "dev", "test")
        ret = fab_tasks.cfn_delete(force=True)
        self.assertTrue(ret)
Ejemplo n.º 3
0
    def test_get_all_elbs(self, get_config_function):
        '''
        Check if get_all_elbs() returns all internet facing elbs.
        Args:
            get_config_function: mock of get_config() function

        '''
        basic_config_mock = yaml.load(set_up_basic_config())
        get_config_function.return_value = config.ConfigParser(
            basic_config_mock, "unittest_stack_name", "dev", "test")

        all_elbs = fab_tasks.get_all_elbs()
        self.assertEqual(all_elbs, ["unittest"])
 def test_support_old_bootstrap_cfn(
         self, get_stack_name_function, get_public_elbs_fucntion,
         get_zone_id_function, get_legacy_name_function,
         get_zone_name_function, get_connection_function,
         get_config_function, get_config_process_function,
         get_env_application_function, get_env_tag_function):
     get_connection_function.side_effect = self.connection_side_effect
     basic_config_mock = yaml.load(set_up_basic_config())
     get_config_function.return_value = config.ConfigParser(
         basic_config_mock, "unittest-dev-12345678", "dev", "test",
         "default")
     ret = fab_tasks.support_old_bootstrap_cfn("unittest-dev-12345678")
     self.assertTrue(ret)
Ejemplo n.º 5
0
    def test_cfn_create_without_ssl(self, get_stack_name_function,
                                    get_first_public_elb_function,
                                    get_zone_id_function,
                                    get_legacy_name_function,
                                    get_zone_name_function,
                                    get_config_function,
                                    get_connection_function,
                                    get_cloudformation_tags_function,
                                    process_function,
                                    get_events_function,
                                    _validate_fabric_env_function):
        '''
        create a stack without uploading ssl
        Note: when testing creating stack, get_stack_name.return_value
         should be different from stack_name inside cfn_mock()
         so that Cloudformation.stack_missing() in utils.tail() will be True
        Args:
            get_stack_name_function:
            get_first_public_elb_function:
            get_zone_id_function:
            get_legacy_name_function:
            get_zone_name_function:
            get_config_function:
            get_connection_function: to mock get_connection(klass)
            get_cloudformation_tags_function: to mock cfn.create() whose arguments include it
            process_function: to mock cfn.create() whose arguments include ConfigParser.process
            get_events_function: this is to mock utils.tail() which includes get_events()

        Returns:

        '''
        # this does not mock fabric env value actually.
        # I just mock the whole function to do nothing for test simplicity.
        _validate_fabric_env_function.side_effect = {"env.keyname.return_value": "default"}

        get_connection_function.side_effect = self.connection_side_effect
        basic_config_mock = yaml.load(set_up_basic_config())
        get_config_function.return_value = config.ConfigParser(
            basic_config_mock, "unittest_stack_name", "dev", "test", "default")
        ret = fab_tasks.cfn_create(False)
        self.assertTrue(ret)
Ejemplo n.º 6
0
    def test_get_all_elbs_with_filter(self, get_config_function):
        '''
        Check if get_all_elbs() returns correct Internet facing ELB,
        given a filter that would should match only a specific name.
        Args:
            get_config_function: mock of get_config() function

        '''
        basic_config_mock = yaml.load(set_up_basic_config())
        basic_config_mock['elb'].append({
            'hosted_zone': 'unittest.dsd.io.',
            'name': 'unittest2',
            'scheme': 'internet-facing'
        })

        get_config_function.return_value = config.ConfigParser(
            basic_config_mock, "unittest_stack_name", "dev", "test")

        regex = re.compile('unittest2')
        filtered_elbs = fab_tasks.get_all_elbs(regex.match)
        self.assertEqual(filtered_elbs, ["unittest2"])