<commit_before># Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ironic_lib import utils as irlib_utils
import mock
from oslo_concurrency import processutils
import six

from ironic.common import exception
from ironic.common import states
from ironic.common import utils as com_utils
from ironic.conductor import task_manager
from ironic.conductor import utils
from ironic.drivers.modules.ansible import deploy as ansible_deploy
from ironic.drivers.modules import deploy_utils
from ironic.drivers.modules import fake
from ironic.drivers.modules import pxe
from ironic.tests.unit.conductor import mgr_utils
from ironic.tests.unit.db import base as db_base
from ironic.tests.unit.objects import utils as object_utils

INSTANCE_INFO = {
    'image_source': 'fake-image',
    'image_url': 'http://image',
    'image_checksum': 'checksum',
    'image_disk_format': 'qcow2',
    'root_mb': 5120,
    'swap_mb': 0,
    'ephemeral_mb': 0
}

DRIVER_INFO = {
    'deploy_kernel': 'glance://deploy_kernel_uuid',
    'deploy_ramdisk': 'glance://deploy_ramdisk_uuid',
    'ansible_username': 'test',
    'ansible_key_file': '/path/key',
    'ipmi_address': '127.0.0.1',
}
DRIVER_INTERNAL_INFO = {
    'is_whole_disk_image': True,
    'clean_steps': []
}


class AnsibleDeployTestCaseBase(db_base.DbTestCase):

    def setUp(self):
        super(AnsibleDeployTestCaseBase, self).setUp()
        self.config(enabled_deploy_interfaces='direct,iscsi,ansible')
        mgr_utils.mock_the_extension_manager(driver='ipmi',
                                             namespace='ironic.hardware.types')
        node = {
            'driver': 'ipmi',
            'deploy_interface': 'ansible',
            'instance_info': INSTANCE_INFO,
            'driver_info': DRIVER_INFO,
            'driver_internal_info': DRIVER_INTERNAL_INFO,
        }
        self.node = object_utils.create_test_node(self.context, **node)


class TestAnsibleMethods(AnsibleDeployTestCaseBase):

    def test__parse_ansible_driver_info(self):
        self.node.driver_info['ansible_deploy_playbook'] = 'spam.yaml'
        playbook, user, key = ansible_deploy._parse_ansible_driver_info(
            self.node, 'deploy')
        self.assertEqual('spam.yaml', playbook)
        self.assertEqual('test', user)
        self.assertEqual('/path/key', key)

    def test__parse_ansible_driver_info_defaults(self):
        self.node.driver_info.pop('ansible_username')
        self.node.driver_info.pop('ansible_key_file')
        self.config(group='ansible',
                    default_username='spam',
                    default_key_file='/ham/eggs',
                    default_deploy_playbook='parrot.yaml')
        playbook, user, key = ansible_deploy._parse_ansible_driver_info(
            self.node, 'deploy')
        # testing absolute path to the playbook
        self.assertEqual('parrot.yaml', playbook)
        self.assertEqual('spam', user)
        self.assertEqual('/ham/eggs', key)

    @mock.patch.object(ansible_deploy.LOG, 'warning', autospec=True)
    def test__parse_ansible_driver_info_deprecated_opts(self, warn_mock):
        self.node.driver_info[
            'ansible_deploy_username'] = self.node.driver_info.pop(
                'ansible_username')
        self.node.driver_info[
            'ansible_deploy_key_file'] = self.node.driver_info.pop(
                'ansible_key_file')
        playbook, user, key = ansible_deploy._parse_ansible_driver_info(
            self.node, 'deploy')
        self.assertEqual(ansible_deploy.CONF.ansible.default_deploy_playbook,
                         playbook)
        self.assertEqual('test', user)
        self.assertEqual('/path/key', key)
        self.assertEqual(2, warn_mock.call_count)
        # check that we remeber about warnings havig been displayed
        playbook, user, key = ansible_deploy._parse_ansible_driver_info(
            self.node, 'deploy')
        self.assertEqual(2, warn_mock.call_count)

    def test__parse_ansible_driver_info_no_playbook(self):
        self.assertRaises(exception.IronicException,
                          ansible_deploy._parse_ansible_driver_info,
                          self.node, 'test')
<commit_msg>remeber spelling error<commit_after># Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ironic_lib import utils as irlib_utils
import mock
from oslo_concurrency import processutils
import six

from ironic.common import exception
from ironic.common import states
from ironic.common import utils as com_utils
from ironic.conductor import task_manager
from ironic.conductor import utils
from ironic.drivers.modules.ansible import deploy as ansible_deploy
from ironic.drivers.modules import deploy_utils
from ironic.drivers.modules import fake
from ironic.drivers.modules import pxe
from ironic.tests.unit.conductor import mgr_utils
from ironic.tests.unit.db import base as db_base
from ironic.tests.unit.objects import utils as object_utils

INSTANCE_INFO = {
    'image_source': 'fake-image',
    'image_url': 'http://image',
    'image_checksum': 'checksum',
    'image_disk_format': 'qcow2',
    'root_mb': 5120,
    'swap_mb': 0,
    'ephemeral_mb': 0
}

DRIVER_INFO = {
    'deploy_kernel': 'glance://deploy_kernel_uuid',
    'deploy_ramdisk': 'glance://deploy_ramdisk_uuid',
    'ansible_username': 'test',
    'ansible_key_file': '/path/key',
    'ipmi_address': '127.0.0.1',
}
DRIVER_INTERNAL_INFO = {
    'is_whole_disk_image': True,
    'clean_steps': []
}


class AnsibleDeployTestCaseBase(db_base.DbTestCase):

    def setUp(self):
        super(AnsibleDeployTestCaseBase, self).setUp()
        self.config(enabled_deploy_interfaces='direct,iscsi,ansible')
        mgr_utils.mock_the_extension_manager(driver='ipmi',
                                             namespace='ironic.hardware.types')
        node = {
            'driver': 'ipmi',
            'deploy_interface': 'ansible',
            'instance_info': INSTANCE_INFO,
            'driver_info': DRIVER_INFO,
            'driver_internal_info': DRIVER_INTERNAL_INFO,
        }
        self.node = object_utils.create_test_node(self.context, **node)


class TestAnsibleMethods(AnsibleDeployTestCaseBase):

    def test__parse_ansible_driver_info(self):
        self.node.driver_info['ansible_deploy_playbook'] = 'spam.yaml'
        playbook, user, key = ansible_deploy._parse_ansible_driver_info(
            self.node, 'deploy')
        self.assertEqual('spam.yaml', playbook)
        self.assertEqual('test', user)
        self.assertEqual('/path/key', key)

    def test__parse_ansible_driver_info_defaults(self):
        self.node.driver_info.pop('ansible_username')
        self.node.driver_info.pop('ansible_key_file')
        self.config(group='ansible',
                    default_username='spam',
                    default_key_file='/ham/eggs',
                    default_deploy_playbook='parrot.yaml')
        playbook, user, key = ansible_deploy._parse_ansible_driver_info(
            self.node, 'deploy')
        # testing absolute path to the playbook
        self.assertEqual('parrot.yaml', playbook)
        self.assertEqual('spam', user)
        self.assertEqual('/ham/eggs', key)

    @mock.patch.object(ansible_deploy.LOG, 'warning', autospec=True)
    def test__parse_ansible_driver_info_deprecated_opts(self, warn_mock):
        self.node.driver_info[
            'ansible_deploy_username'] = self.node.driver_info.pop(
                'ansible_username')
        self.node.driver_info[
            'ansible_deploy_key_file'] = self.node.driver_info.pop(
                'ansible_key_file')
        playbook, user, key = ansible_deploy._parse_ansible_driver_info(
            self.node, 'deploy')
        self.assertEqual(ansible_deploy.CONF.ansible.default_deploy_playbook,
                         playbook)
        self.assertEqual('test', user)
        self.assertEqual('/path/key', key)
        self.assertEqual(2, warn_mock.call_count)
        # check that we remember about warnings havig been displayed
        playbook, user, key = ansible_deploy._parse_ansible_driver_info(
            self.node, 'deploy')
        self.assertEqual(2, warn_mock.call_count)

    def test__parse_ansible_driver_info_no_playbook(self):
        self.assertRaises(exception.IronicException,
                          ansible_deploy._parse_ansible_driver_info,
                          self.node, 'test')

{'fraction_non_alphanumeric': 0.09698782311471908, 'fraction_numerical': 0.004058961760307627, 'mean_word_length': 3.1374281926646046, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4736965', 'n_tokens_mistral': 2875, 'n_tokens_neox': 2741, 'n_words': 596}