def hardware(request, config): """Fixture for manage the hardware layer. - start/stop/reboot libvirt/IPMI(/MaaS?) nodes - snapshot/revert libvirt nodes (fuel-devops only) - block/unblock libvirt networks/interfaces (fuel-devops only) This fixture should get a hardware configuration from 'config' object or create a virtual/baremetal underlay using EnvironmentManager. Creates a snapshot 'hardware' with ready-to-use virtual environment (Only for config.hardware.manager='devops'): - just created virtual nodes in power-on state - node volumes filled with necessary content - node network interfaces connected to necessary devices config.hardware.manager: one of ('devops', 'maas', None) config.hardware.config: path to the config file for the manager config.hardware.current_snapshot = Latest created or reverted snapshot :rtype EnvironmentModel: if config.hardware.manager == 'devops' :rtype EnvironmentManagerEmpty: if config.hardware.manager == 'empty' """ env = None manager = config.hardware.manager if manager == 'empty': # No environment manager is used. # 'config' should contain config.underlay.ssh settings # 'config' should contain config.underlay.current_snapshot setting env = envmanager_empty.EnvironmentManagerEmpty(config=config) elif manager == 'devops': # fuel-devops environment manager is used. # config.underlay.ssh settings can be empty or witn SSH to existing env # config.underlay.current_snapshot env = envmanager_devops.EnvironmentManager(config=config) else: raise Exception("Unknown hardware manager: '{}'".format(manager)) # for devops manager: power on nodes and wait for SSH # for empty manager: do nothing # for maas manager: provision nodes and wait for SSH if not env.has_snapshot(ext.SNAPSHOT.hardware): env.start() env.create_snapshot(ext.SNAPSHOT.hardware) def fin(): if settings.SHUTDOWN_ENV_ON_TEARDOWN: LOG.info("Shutdown environment...") env.stop() request.addfinalizer(fin) return env
def main(): """Create fuel-devops environment from template""" config = config_fixtures.config() env = envmanager_devops.EnvironmentManager(config=config) if not env.has_snapshot(ext.SNAPSHOT.hardware): env.create_snapshot(ext.SNAPSHOT.hardware)