def get_corosync_autoconfig(): """ Automatically detect the configuration for corosync. :return: dictionary containing 'result' or 'error'. """ ring0 = get_ring0() if not ring0: return agent_error('Failed to detect ring0 interface') ring1_ipaddr, ring1_prefix = generate_ring1_network(ring0) try: ring1 = detect_ring1(ring0, ring1_ipaddr, ring1_prefix) except RingDetectionError as e: return agent_error(e.message) return agent_result({ 'interfaces': { ring0.name: { 'dedicated': False, 'ipaddr': ring0.ipv4_address, 'prefix': ring0.ipv4_prefixlen }, ring1.name: { 'dedicated': True, 'ipaddr': ring1.ipv4_address, 'prefix': ring1.ipv4_prefixlen } }, 'mcast_port': ring1.mcastport })
def get_corosync_autoconfig(self): with self._lock: port_names = {'tcp': 'eth', 'o2ib': 'ib'} inet4_addresses = [] names = [] for inet4_address in self.network_interfaces.keys(): interface = self.network_interfaces[inet4_address] inet4_addresses.append(inet4_address) names.append( '%s%s' % (port_names[interface['type']], interface['interface_no'])) return agent_result({ 'interfaces': { names[0]: { 'dedicated': False, 'ipaddr': inet4_addresses[0], 'prefix': 24 }, names[1]: { 'dedicated': True, 'ipaddr': inet4_addresses[1], 'prefix': 24 } }, 'mcast_port': self.state['corosync'].mcast_port })
def start_target(ha_label): ''' Start the high availability target Return: Value using simple return protocol ''' # HYD-1989: brute force, try up to 3 times to start the target i = 0 while True: i += 1 error = AgentShell.run_canned_error_message([ 'crm_resource', '-r', ha_label, '-p', 'target-role', '-m', '-v', 'Started' ]) if error: return agent_error(error) # now wait for it to start _wait_target(ha_label, True) # and make sure it didn't start but (the RA) fail(ed) rc, stdout, stderr = AgentShell.run_old(['crm_mon', '-1']) failed = True for line in stdout.split("\n"): if line.lstrip().startswith(ha_label): if line.find("FAILED") < 0: failed = False if failed: # try to leave things in a sane state for a failed mount error = AgentShell.run_canned_error_message([ 'crm_resource', '-r', ha_label, '-p', 'target-role', '-m', '-v', 'Stopped' ]) if error: return agent_error(error) if i < 4: console_log.info("failed to start target %s" % ha_label) else: return agent_error("Failed to start target %s" % ha_label) else: location = get_resource_location(ha_label) if not location: return agent_error("Started %s but now can't locate it!" % ha_label) return agent_result(location)
def install_packages(self, repos, packages): for package in packages: try: self.state['packages'][ package] = self._simulator.available_packages( self.node_type)[package] except KeyError: raise RuntimeError( "Package '%s' not found (available: %s)!" % (package, self._simulator.available_packages( self.node_type))) self.save() return agent_result(self.scan_packages())
def install_packages(repos, packages): """ Explicitly evaluate and install or update any specific-version dependencies and satisfy even if that involves installing an older package than is already installed. Primary use case is installing lustre-modules, which depends on a specific kernel package. :param repos: List of strings, yum repo names :param packages: List of strings, yum package names :return: package report of the format given by the lustre device plugin """ if packages != []: yum_util('clean') out = yum_util('requires', enablerepo=repos, packages=packages) for requirement in [l.strip() for l in out.strip().split("\n")]: match = re.match("([^\)/]*) = (.*)", requirement) if match: require_package, require_version = match.groups() packages.append("%s-%s" % (require_package, require_version)) yum_util('install', enablerepo=repos, packages=packages) # So now we have installed the packages requested, we will also make sure that any installed packages we # have that are already installed are updated to our presumably better versions. update_packages = yum_check_update(repos) if update_packages: daemon_log.debug( "The following packages need update after we installed IML packages %s" % update_packages) yum_util('update', packages=update_packages, enablerepo=repos) error = _check_HYD4050() if error: return agent_error(error) return agent_result(lustre.scan_packages())
def test_install_packages(self): self.add_commands(CommandCaptureCommand(('yum', 'clean', 'all', '--enablerepo=*')), CommandCaptureCommand(('repoquery', '--requires', '--enablerepo=myrepo', 'foo', 'bar'), stdout="""/usr/bin/python python >= 2.4 python(abi) = 2.6 yum >= 3.2.29 /bin/sh kernel = 2.6.32-279.14.1.el6_lustre lustre-backend-fs """), CommandCaptureCommand(('yum', 'install', '-y', '--enablerepo=myrepo', 'foo', 'bar', 'kernel-2.6.32-279.14.1.el6_lustre')), CommandCaptureCommand(('yum', 'check-update', '-q', '--disablerepo=*', '--enablerepo=myrepo'), stdout=""" jasper-libs.x86_64 1.900.1-16.el6_6.3 myrepo """), CommandCaptureCommand(('yum', 'update', '-y', '--enablerepo=myrepo', 'jasper-libs.x86_64')), CommandCaptureCommand(('grubby', '--default-kernel'), stdout='/boot/vmlinuz-2.6.32-504.3.3.el6.x86_64')) def isfile(arg): return True with patch('os.path.isfile', side_effect=isfile): self.assertEqual(agent_updates.install_packages(['myrepo'], ['foo', 'bar']), agent_result({})) self.assertRanAllCommandsInOrder()
def start_target(self, ha_label): resource = self._cluster.start(ha_label) return agent_result(resource['started_on'])
def unconfigure_target_ha(self, primary, ha_label, uuid): return agent_result( self._cluster.unconfigure(self.nodename, ha_label, primary))
def configure_target_ha(self, primary, device, ha_label, uuid, mount_point): return agent_result( self._cluster.configure(self.nodename, device, ha_label, uuid, primary, mount_point))