コード例 #1
0
def test_invalid_command():
    returncode, return_list, error_list = simple_command().run("non-existant")

    assert returncode != 0
    assert len(return_list) == 0
    assert len(error_list) >= 1
    assert 'not found' in error_list[0]
コード例 #2
0
def test_non_string_command():
    try:
        returncode, return_list, error_list = simple_command().run(
            {"stuff": "stuff"})
        assert False
    except ValueError:
        assert True
コード例 #3
0
    def is_installed(self, package):

        if not cross_version.isstring(package):
            raise ValueError("Package name is not a string")

        exists_command = ""

        if self.__package_manager == "yum":
            exists_command = "yum list installed " + package
        elif self.__package_manager == "apt":
            exists_command = "dpkg -s " + package

        returncode, return_list, error_list = simple_command.simple_command(
        ).run(exists_command)

        if self.__package_manager == "yum":
            if returncode == 0:
                return True
            else:
                return False
        elif self.__package_manager == "apt":
            if returncode == 0:
                return True
            else:
                return False
コード例 #4
0
def test_invalid_command():
	returncode, return_list, error_list = simple_command().run("non-existant")

	assert returncode != 0
	assert len(return_list) == 0
	assert len(error_list) >= 1
	assert 'not found' in error_list[0]
コード例 #5
0
def test_single_command():
    returncode, return_list, error_list = simple_command().run("ls /")

    assert returncode == 0
    assert len(return_list) >= 1
    assert len(error_list) == 0
    assert 'root' in return_list
    assert 'bin' in return_list
コード例 #6
0
def test_single_command():
	returncode, return_list, error_list = simple_command().run("ls /")
	
	
	assert returncode == 0
	assert len(return_list) >= 1
	assert len(error_list) == 0
	assert 'root' in return_list
	assert 'bin' in return_list
コード例 #7
0
def test_single_command_extra():
	returncode, return_list, error_list = simple_command().run("cat", ["stuff", 'not','exist'])
	
	assert returncode == 0
	assert len(return_list) >= 1
	assert len(error_list) == 0
	assert "stuff" in return_list
	assert 'not' in return_list
	assert not 'cat' in return_list
	assert 'exist' in return_list
コード例 #8
0
	def install(self, package, version=None):
		
		if not cross_version.isstring(package):
			raise ValueError("Package name is not a string")
		
		install_command = ""
		
		if self.__package_manager == "yum":
			install_command = "yum install -y " + package
		elif self.__package_manager == "apt":
			returncode, return_list, error_list = simple_command.simple_command().run("apt-get update")
			install_command = "apt-get install -y " + package
		
		returncode, return_list, error_list = simple_command.simple_command().run(install_command)
		
		if returncode == 0:
			return True
		else:
			return False
コード例 #9
0
def test_single_command_extra():
    returncode, return_list, error_list = simple_command().run(
        "cat", ["stuff", 'not', 'exist'])

    assert returncode == 0
    assert len(return_list) >= 1
    assert len(error_list) == 0
    assert "stuff" in return_list
    assert 'not' in return_list
    assert not 'cat' in return_list
    assert 'exist' in return_list
コード例 #10
0
    def install(self, package, version=None):

        if not cross_version.isstring(package):
            raise ValueError("Package name is not a string")

        install_command = ""

        if self.__package_manager == "yum":
            install_command = "yum install -y " + package
        elif self.__package_manager == "apt":
            returncode, return_list, error_list = simple_command.simple_command(
            ).run("apt-get update")
            install_command = "apt-get install -y " + package

        returncode, return_list, error_list = simple_command.simple_command(
        ).run(install_command)

        if returncode == 0:
            return True
        else:
            return False
コード例 #11
0
	def uninstall(self, package):	
		if not cross_version.isstring(package):
			raise ValueError("Package name is not a string")
		
		uninstall_command = ""
		
		if self.__package_manager == "yum":
			install_command = "yum remove -y " + package
		elif self.__package_manager == "apt":
			install_command = "apt-get remove -y --purge " + package
		
		returncode, return_list, error_list = simple_command.simple_command().run(install_command)

		if returncode == 0:
			return True
		else:
			return False
コード例 #12
0
    def uninstall(self, package):
        if not cross_version.isstring(package):
            raise ValueError("Package name is not a string")

        uninstall_command = ""

        if self.__package_manager == "yum":
            install_command = "yum remove -y " + package
        elif self.__package_manager == "apt":
            install_command = "apt-get remove -y --purge " + package

        returncode, return_list, error_list = simple_command.simple_command(
        ).run(install_command)

        if returncode == 0:
            return True
        else:
            return False
コード例 #13
0
def test_available_ports():
	test_obj = networking()
	
	port_list = []
	
	if os_data.os_info().matches(os_data.os_match('linux')):
		code, output, error = simple_command().run('netstat -tunap | grep LISTEN')
		
		for line in output:
			line_list = line.split(" ")
			
			new_line = []
			
			for item in line_list:
				if item != "":
					new_line.append(item)
			
			listen_section = new_line[3]
			
			listen_split = listen_section.split(":")
			
			port = listen_split[len(listen_split) - 1]
			
			port_list.append(int(port))
	
		for port in port_list:
			assert test_obj.is_port_available(port) == False

		i = 1
		for j in range(5): 
			while i in port_list and i <= 65535:
				i += 5
			
			if i == 65535:
				assert False
			
			assert test_obj.is_port_available(i) == True
			i += 5
コード例 #14
0
	def is_installed(self, package):
		
		if not cross_version.isstring(package):
			raise ValueError("Package name is not a string")
		
		exists_command = ""
		
		if self.__package_manager == "yum":
			exists_command = "yum list installed " + package
		elif self.__package_manager == "apt":
			exists_command = "dpkg -s " + package
		
		returncode, return_list, error_list = simple_command.simple_command().run(exists_command)
		
		if self.__package_manager == "yum":
			if returncode == 0:
				return True
			else:
				return False
		elif self.__package_manager == "apt":
			if returncode == 0:
				return True
			else:
				return False
コード例 #15
0
ファイル: base.py プロジェクト: bocajspear1/badadmin
	def command(self):
		return simple_command()
コード例 #16
0
def test_non_string_command():
	try:
		returncode, return_list, error_list = simple_command().run({"stuff": "stuff"})
		assert False
	except ValueError:
		assert True
コード例 #17
0
	def __fill(self):
		
		if os_data.os_info().matches(os_data.os_match('linux')):
			cmd = simple_command.simple_command()
			code, output, errors = cmd.run("ip addr")
			
			if code == 0:
			
				output = "\n".join(output)
				
				raw_interfaces = re.split("\n[0-9]+: ", "\n" + output)
				
				for interface in raw_interfaces:
					if interface == "":
						continue
						
					data_split = interface.split(": ")
					
					interface_name = data_split[0]
					del data_split[0]
					interface_info = ": ".join(data_split)
					
					self.__interfaces[interface_name] = {}
					info_split = interface_info.split("\n")
					for line in info_split:
						if line.startswith("  "):
							line = line.strip()
							line_split = line.split(" ")
							if line.startswith("link"):
								if len(line_split) == 4:
									
									if not 'mac' in self.__interfaces[interface_name]:
										self.__interfaces[interface_name]['mac'] = {}
									
									self.__interfaces[interface_name]['mac']['address'] = line_split[1]
									self.__interfaces[interface_name]['mac']['broadcast'] = line_split[3]
									
							elif line.startswith("inet "):
								if len(line_split) >= 4:
									ipv4_data = line_split[1]
									ip_split = ipv4_data.split("/")
									
									addr = ip_split[0]
									mask = ip_split[1]
									
									if not 'ipv4' in self.__interfaces[interface_name]:
										self.__interfaces[interface_name]['ipv4'] = {}
									
									self.__interfaces[interface_name]['ipv4']['address'] = addr
									self.__interfaces[interface_name]['ipv4']['mask'] = mask
									if "brd" in line:
										self.__interfaces[interface_name]['ipv4']['broadcast'] = line_split[3]
									
							elif line.startswith("inet6 "):
								if len(line_split) >= 4:
									ipv6_data = line_split[1]
									ip_split = ipv6_data.split("/")
									
									addr = ip_split[0]
									mask = ip_split[1]
									
									if not 'ipv6' in self.__interfaces[interface_name]:
										self.__interfaces[interface_name]['ipv6'] = {}
									
									self.__interfaces[interface_name]['ipv6']['address'] = addr
									self.__interfaces[interface_name]['ipv6']['mask'] = mask
									if "brd" in line:
										self.__interfaces[interface_name]['ipv6']['broadcast'] = line_split[3]
					
				#~ print(self.__interfaces)
			else:
				print("Error running ip addr")
		elif os_data.os_info().matches(os_data.os_match('windows')):
			pass
コード例 #18
0
ファイル: base.py プロジェクト: bocajspear1/badadmin
 def command(self):
     return simple_command()