def _deploy(self): self._log.info("Starting deployment") if self.args.cloud == "all": self.args.cloud = "all_" config_org = common.get_org(self.args, self.args.config_org) code_org = common.get_org(self.args, self.args.code_org) config_files = common.get_files( config_org, self.args.config_repo, self.args.cloud, self.args.config_version, ) # code repo should contain any lists or maps that define # security policies # and operating requirements. The code repo should be public. code_files = common.get_files( code_org, self.args.code_repo, self.args.cloud, self.args.config_version, ) config_hash = common.get_hash_of_latest_commit( config_org, self.args.config_repo, self.args.config_version ) code_hash = common.get_hash_of_latest_commit( code_org, self.args.code_repo, self.args.code_version ) testing_ending = f"{config_hash[:7]}-{code_hash[:7]}" return deploy(self.args, code_files, config_files, testing_ending)
def test_deploy( mocker, command_line_args, code_files, config_files, short_code_config_hash ): """ Checks, that when `deploy` being called: 1) `TerraformDeployer` instantiated twice. 2) `TerraformDeployer.run` called for two instances, and `TerraformDeployer.delete` called for test instance. 3) No errors raised """ test_deployment = Mock() real_deployment = Mock() test_deployment.current_state = { "serial": 1, "lineage": str(uuid4()), "some_key": 123, } # since real_deploy changes it's state twice, we use PropertyMock here to return different # state per __get__ invocation type(real_deployment).current_state = PropertyMock( side_effect=[ {}, {"serial": 2, "lineage": str(uuid4()), "some_key": 123}, {"serial": 2, "lineage": str(uuid4()), "some_key": 123}, ] ) deployer = mocker.patch("deployer.TerraformDeployer") deployer.side_effect = [test_deployment, real_deployment] deploy(command_line_args, code_files, config_files, short_code_config_hash) deployer.assert_has_calls( [ call( command_line_args, code_files, config_files, short_code_config_hash, ), call(command_line_args, code_files, config_files), ] ) test_deployment.run.assert_called_once() test_deployment.delete.assert_called_once() real_deployment.run.assert_called_once()
def test_deploy_different_states( mocker, command_line_args, code_files, config_files, test_state, real_state ): """ Checks that wrong state leads to wrong state error. First case: state of test deployment equal to actual prod state, so we don't neet to deploy. Second case: same as first, but state contains keys, that are not cleaned by `_prepare_state_for_compare` function Third case: after prod deployment, if states different, then something gone wrong. """ test_deployment = Mock() real_deployment = Mock() test_deployment.current_state = test_state real_deployment.current_state = real_state deployer = mocker.patch("deployer.TerraformDeployer") deployer.side_effect = [test_deployment, real_deployment] with pytest.raises(WrongStateError): deploy(command_line_args, code_files, config_files)
def deploy_component(): while True: time.sleep(5) print("+++++++ Start +++++++++++++++++") j=0 #print("Available Resources:",avai_resources) #print("Placement Plan:", "C1:", placement_plan[0],"C2:", placement_plan[1], "C3:", placement_plan[2]) #print(R[placement_plan[0]-1]) #Step1 #Check the available resources from controller #List of Nodes ######Fog #N2='192.168.1.149' #N1='54.77.247.42' #large #N1='34.241.78.252' #xlarge #N1='63.34.50.93'' ' #2xlarge #N1='99.81.111.8' #####if len (avai_resources)!=0: ###Nodes=[CN2,CN3,CN1] ####for i in range (3): ####Nodes.append(Resources[placement_plan[i]-1]) #Nodes.append(N2) Components=[C1,C2,C3] ####Components=[] ####for i in range(3): ####Components.append(Components_AD[i]) S1='firedetect' S2='svm_train_predict' S3='dm' #Components.append(c2) #c2="c1_event_detectionv1" #List of services #S1='svm_train_predict' #S2='svm_train_predict' #S2='DL_train_pred' #Services.append(S2) #Step2 #Calculate best placement plan start_time = time.time() #Step3 t=23 h=50 #for i in range(len(placement_plan)): #placement_plannow.append(placement_plannow[i]) """for i in range(len(Nodes)): #N="N"+str(Resources.index(Nodes[i])+1) #print(N) #print(check.rs.look_for_nodeavai(N)) if check.rs.look_for_nodeavai(N)==1: try: deployer.deploy(Components[i],Nodes[i],i+j) # break except: print("Problem of Deplyment") break else: break if str(Nodes[i])[:3]=="192": time.sleep(16) else: time.sleep(10) if check.rs.look_for_nodeavai(N)==1: try: requestor.send_data3(Nodes[i],Services[i],i+j,"/home/aymen/a.txt",t,h) except: print("Problem of request") break else: break if i==2: print("All componenents are deployed on machines") #else: #j=j+1 ####else: ####time.sleep(5) """ #Call the deployer to deploy Component on nodes deployer.deploy(Components[0],Nodes[0],1) deployer.deploy(Components[1],Nodes[1],2) deployer.deploy(Components[2],Nodes[2],4) ########print("--- %s Deployment time in seconds ---" % (time.time() - start_time)) #time.sleep(10) #print("New Per",check.rs.look_for_nodeper("192.168.1.149")) #Step4 #requestor.DB_connection() #C1_ED requestor.send_data3(Nodes[0],S1,1,"/home/aymen/a.txt",t,h) #for i in range(3): #requestor.send_data3(Nodes[1],Services[i],i,"/home/aymen/a.txt",t,h) #time.sleep(10) #time.sleep(17) #C2_ED requestor.send_data(Nodes[1],S2,2) #requestor.send_data(Nodes[1],Services[1],1) #C3_ED requestor.send_data4(Nodes[2],S3,4) print("--- %s Execution time in seconds ---" % (time.time() - start_time))
#!/usr/bin/env python3 import sys sys.path.append("../deployment") import deployer from deployer import Deployer from web3_interface import Web3Interface from tx_checker import fails, succeeds web3 = Web3Interface().w3 web3.miner.start(1) deployer = Deployer() owner = web3.eth.accounts[0] new_owner = web3.eth.accounts[1] gas = 5000000 gas_price = 20000000000 tx = {"from": owner, "value": 0, "gas": gas, "gasPrice": gas_price} (ownable_contract, tx_hash) = deployer.deploy("./build/", "OwnableMock", tx,) receipt = web3.eth.waitForTransactionReceipt(tx_hash) assert receipt.status == 1 functions = ownable_contract.functions def get_owner(): return functions.owner().call() assert get_owner() == owner succeeds("Transfer ownership succeeds.", functions.transferOwnership(new_owner).transact(tx)) assert get_owner() == new_owner web3.miner.stop()