# Path: bifrost/inventory.py
#     SDK_LOADED = True
#     SDK_LOADED = False
# DOCUMENTATION = '''
# Bifrost Inventory Module
# ========================
# 
# This is a dynamic inventory module intended to provide a platform for
# consistent inventory information for Bifrost.
# 
# The inventory supplies two distinct groups by default:
# 
#     - localhost
#     - baremetal
# 
# The localhost group is required for Bifrost to perform local actions to
# bifrost for local actions such as installing Ironic.
# 
# The baremetal group contains the hosts defined by the data source along with
# variables extracted from the data source. The variables are defined on a
# per-host level which allows explicit actions to be taken based upon the
# variables.
# 
# It is also possible for users to specify additional per-host groups by
# simply setting the host_groups variable in the inventory file. See below for
# an example JSON file.
# 
# The default group can also be changed by setting the DEFAULT_HOST_GROUPS
# variable to contain the desired groups separated by whitespace as follows:
# 
# DEFAULT_HOST_GROUPS="foo bar zoo"
# 
# In case of provisioning virtual machines, additional per-VM groups can
# be set by simply setting the test_vm_groups[$host] variable to a list
# of desired groups. Moreover, users can override the default 'baremetal'
# group by assigning a list of default groups to the test_vm_default_group
# variable.
# 
# Presently, the base mode of operation reads a JSON/YAML file in the format
# originally utilized by bifrost and returns structured JSON that is
# interpreted by Ansible.
# 
# Conceivably, this inventory module can be extended to allow for direct
# processing of inventory data from other data sources such as a configuration
# management database or other inventory data source to provide a consistent
# user experience.
# 
# How to use?
# -----------
# 
#     export BIFROST_INVENTORY_SOURCE=/tmp/baremetal.[json|yaml]
#     ansible-playbook playbook.yaml -i inventory/bifrost_inventory.py
# 
# One can also just directly invoke bifrost_inventory.py in order to see the
# resulting JSON output.  This module also has a feature to support the
# pass-through of a pre-existing JSON document, which receives updates and
# formatting to be supplied to Ansible.  Ultimately the use of JSON will be
# far more flexible and should be the preferred path forward.
# 
# Example JSON Element:
# 
# {
#   "node1": {
#     "uuid": "a8cb6624-0d9f-c882-affc-046ebb96ec01",
#     "host_groups": [
#         "nova",
#         "neutron"
#     ],
#     "driver_info": {
#       "ipmi_target_channel": "0",
#       "ipmi_username": "ADMIN",
#       "ipmi_address": "192.168.122.1",
#       "ipmi_target_address": "0",
#       "ipmi_password": "undefined",
#       "ipmi_bridging": "single"
#     },
#     "nics": [
#       {
#         "mac": "00:01:02:03:04:05"
#       }.
#       {
#         "mac": "00:01:02:03:04:06"
#       }
#    ],
#    "driver": "ipmi",
#    "ipv4_address": "192.168.122.2",
#    "properties": {
#       "cpu_arch": "x86_64",
#       "ram": "3072",
#       "disk_size": "10",
#       "cpus": "1"
#     },
#     "name": "node1"
#   }
# }
# 
# Utilizing ironic as the data source
# -----------------------------------
# 
# The functionality exists to allow a user to query an existing ironic
# installation for the inventory data.  This is an advanced feature,
# as the node may not have sufficient information to allow for node
# deployment or automated testing, unless DHCP reservations are used.
# 
# This setting can be invoked by setting the source to "ironic"::
# 
#   export BIFROST_INVENTORY_SOURCE=ironic
# 
# Known Issues
# ------------
# 
# At present, this module only supports inventory list mode and is not
# intended to support specific host queries.
# '''
# LOG = log.getLogger(__name__)
# def _parse_config():
# def _prepare_inventory():
# def _process_baremetal_data(data_source, groups, hostvars):
# def _process_sdk(groups, hostvars):
# def main():


from unittest import mock
from bifrost import inventory
from bifrost.tests import base
import openstack
# 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.

"""
test_inventory
----------------------------------

Tests for `inventory` module.
"""





class TestBifrostInventoryUnit(base.TestCase):

    def test_inventory_preparation(self):
        (groups, hostvars) = inventory._prepare_inventory()
        self.assertIn("baremetal", groups)
        self.assertIn("localhost", groups)
        self.assertDictEqual(
            hostvars, {'127.0.0.1': {'ansible_connection': 'local'}})
        localhost_value = dict(hosts=["127.0.0.1"])
        self.assertDictEqual(localhost_value, groups['localhost'])

    @mock.patch.object(openstack, 'connect', autospec=True)
    def test__process_sdk(self, mock_sdk):

# Path: bifrost/inventory.py
#     SDK_LOADED = True
#     SDK_LOADED = False
# DOCUMENTATION = '''
# Bifrost Inventory Module
# ========================
# 
# This is a dynamic inventory module intended to provide a platform for
# consistent inventory information for Bifrost.
# 
# The inventory supplies two distinct groups by default:
# 
#     - localhost
#     - baremetal
# 
# The localhost group is required for Bifrost to perform local actions to
# bifrost for local actions such as installing Ironic.
# 
# The baremetal group contains the hosts defined by the data source along with
# variables extracted from the data source. The variables are defined on a
# per-host level which allows explicit actions to be taken based upon the
# variables.
# 
# It is also possible for users to specify additional per-host groups by
# simply setting the host_groups variable in the inventory file. See below for
# an example JSON file.
# 
# The default group can also be changed by setting the DEFAULT_HOST_GROUPS
# variable to contain the desired groups separated by whitespace as follows:
# 
# DEFAULT_HOST_GROUPS="foo bar zoo"
# 
# In case of provisioning virtual machines, additional per-VM groups can
# be set by simply setting the test_vm_groups[$host] variable to a list
# of desired groups. Moreover, users can override the default 'baremetal'
# group by assigning a list of default groups to the test_vm_default_group
# variable.
# 
# Presently, the base mode of operation reads a JSON/YAML file in the format
# originally utilized by bifrost and returns structured JSON that is
# interpreted by Ansible.
# 
# Conceivably, this inventory module can be extended to allow for direct
# processing of inventory data from other data sources such as a configuration
# management database or other inventory data source to provide a consistent
# user experience.
# 
# How to use?
# -----------
# 
#     export BIFROST_INVENTORY_SOURCE=/tmp/baremetal.[json|yaml]
#     ansible-playbook playbook.yaml -i inventory/bifrost_inventory.py
# 
# One can also just directly invoke bifrost_inventory.py in order to see the
# resulting JSON output.  This module also has a feature to support the
# pass-through of a pre-existing JSON document, which receives updates and
# formatting to be supplied to Ansible.  Ultimately the use of JSON will be
# far more flexible and should be the preferred path forward.
# 
# Example JSON Element:
# 
# {
#   "node1": {
#     "uuid": "a8cb6624-0d9f-c882-affc-046ebb96ec01",
#     "host_groups": [
#         "nova",
#         "neutron"
#     ],
#     "driver_info": {
#       "ipmi_target_channel": "0",
#       "ipmi_username": "ADMIN",
#       "ipmi_address": "192.168.122.1",
#       "ipmi_target_address": "0",
#       "ipmi_password": "undefined",
#       "ipmi_bridging": "single"
#     },
#     "nics": [
#       {
#         "mac": "00:01:02:03:04:05"
#       }.
#       {
#         "mac": "00:01:02:03:04:06"
#       }
#    ],
#    "driver": "ipmi",
#    "ipv4_address": "192.168.122.2",
#    "properties": {
#       "cpu_arch": "x86_64",
#       "ram": "3072",
#       "disk_size": "10",
#       "cpus": "1"
#     },
#     "name": "node1"
#   }
# }
# 
# Utilizing ironic as the data source
# -----------------------------------
# 
# The functionality exists to allow a user to query an existing ironic
# installation for the inventory data.  This is an advanced feature,
# as the node may not have sufficient information to allow for node
# deployment or automated testing, unless DHCP reservations are used.
# 
# This setting can be invoked by setting the source to "ironic"::
# 
#   export BIFROST_INVENTORY_SOURCE=ironic
# 
# Known Issues
# ------------
# 
# At present, this module only supports inventory list mode and is not
# intended to support specific host queries.
# '''
# LOG = log.getLogger(__name__)
# def _parse_config():
# def _prepare_inventory():
# def _process_baremetal_data(data_source, groups, hostvars):
# def _process_sdk(groups, hostvars):
# def main():


# Path: bifrost/tests/unit/test_inventory.py
from unittest import mock
from bifrost import inventory
from bifrost.tests import base
import openstack

# 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.

"""
test_inventory
----------------------------------

Tests for `inventory` module.
"""





class TestBifrostInventoryUnit(base.TestCase):

    def test_inventory_preparation(self):
        (groups, hostvars) = inventory._prepare_inventory()
        self.assertIn("baremetal", groups)
        self.assertIn("localhost", groups)
        self.assertDictEqual(
            hostvars, {'127.0.0.1': {'ansible_connection': 'local'}})
        localhost_value = dict(hosts=["127.0.0.1"])
        self.assertDictEqual(localhost_value, groups['localhost'])

    @mock.patch.object(openstack, 'connect', autospec=True)
    def test__process_sdk(self, mock_sdk):

        (groups, hostvars) = inventory._prepare_inventory()