def test_os_container_crawler_plugin_avoidsetns(self, *args): fc = OSContainerCrawler() for os in fc.crawl(container_id=123, avoid_setns=True): print os assert os == ( 'linux', OSFeature( boottime='unsupported', uptime='unsupported', ipaddr='0.0.0.0', os='os', os_version='os_version', os_kernel='unknown', architecture='unknown'), 'os') for i, arg in enumerate(args): print i, arg if i == 0: # get_osinfo() assert arg.call_count == 1 arg.assert_called_with(mount_point='/a/b/c') elif i == 1: # get_docker_container_rootfs_path assert arg.call_count == 1 arg.assert_called_with(123) else: # exec_dockerinspect assert arg.call_count == 1 arg.assert_called_with(123)
def crawl(self, vm_desc, **kwargs): if psvmi is None: raise NotImplementedError() else: (domain_name, kernel_version, distro, arch) = vm_desc # XXX: not good, context_init was being done once per VM # in previous monolithic model, now it's once per plugin/feature vm_context = psvmi.context_init(domain_name, domain_name, kernel_version, distro, arch) sys = psvmi.system_info(vm_context) feature_attributes = OSFeature(sys.boottime, 'unknown', sys.ipaddr, sys.ostype, sys.osversion, sys.osrelease, sys.osplatform) feature_key = sys.ostype return [(feature_key, feature_attributes, 'os')]
def test_os_vm_crawler_plugin_without_vm(self, *args): fc = os_vm_crawler() for os in fc.crawl(vm_desc=('dn', '2.6', 'ubuntu', 'x86')): assert os == ( 'ostype', OSFeature( boottime=1000, uptime='unknown', ipaddr='1.1.1.1', os='ostype', os_version='osversion', os_kernel='osrelease', architecture='osplatform'), 'os') pass assert args[0].call_count == 1
def test_os_host_crawler_plugin_mountpoint_mode(self, *args): fc = OSHostCrawler() for os in fc.crawl(root_dir='/a'): print os assert os == ( 'linux', OSFeature( boottime='unsupported', uptime='unsupported', ipaddr='0.0.0.0', os='os', os_version='os_version', os_kernel='unknown', architecture='unknown'), 'os') for i, arg in enumerate(args): assert arg.call_count == 1
def test_os_container_crawler_plugin(self, *args): fc = OSContainerCrawler() for os in fc.crawl(container_id=123): print os assert os == ( 'linux', OSFeature( boottime=1000, uptime=1, ipaddr=['1.1.1.1'], os='os', os_version='os_version', os_kernel='platform', architecture='machine'), 'os') for i, arg in enumerate(args): if i > 0: # time.time is called more than once continue assert arg.call_count == 1
def crawl_os_mountpoint(mountpoint='/'): result = osinfo.get_osinfo(mount_point=mountpoint) if result: os_distro = result['os'] os_version = result['version'] else: os_distro = 'unknown' os_version = 'unknown' feature_key = 'linux' feature_attributes = OSFeature( # boot time unknown for img # live IP unknown for img 'unsupported', 'unsupported', '0.0.0.0', os_distro, os_version, 'unknown', 'unknown') return [(feature_key, feature_attributes, 'os')]
def crawl_os(): feature_key = platform.system().lower() try: os_kernel = platform.platform() except: os_kernel = 'unknown' result = osinfo.get_osinfo(mount_point='/') if result: os_distro = result['os'] os_version = result['version'] else: os_distro = 'unknown' os_version = 'unknown' ips = misc.get_host_ip4_addresses() boot_time = psutil.boot_time() uptime = int(time.time()) - boot_time feature_attributes = OSFeature(boot_time, uptime, ips, os_distro, os_version, os_kernel, platform.machine()) return [(feature_key, feature_attributes, 'os')]