Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Changes to Support EVM-based Networks #216

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion resources/ansible/start_nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
- name: ensure all nodes are started using the node manager
hosts: all
become: True
vars:
interval: "{{ interval }}"
tasks:
- name: start
ansible.builtin.command: safenode-manager start --interval 2000
ansible.builtin.command: "safenode-manager start --interval {{ interval }}"
16 changes: 0 additions & 16 deletions resources/ansible/upgrade_faucet.yml

This file was deleted.

39 changes: 23 additions & 16 deletions resources/ansible/upgrade_uploaders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,46 @@
hosts: all
become: True
vars:
safe_version: "{{ safe_version }}"
safe_archive_url: "https://autonomi-cli.s3.eu-west-2.amazonaws.com/safe-{{ safe_version }}-x86_64-unknown-linux-musl.tar.gz"
autonomi_version: "{{ autonomi_version }}"
autonomi_archive_url: "https://autonomi-cli.s3.eu-west-2.amazonaws.com/autonomi-{{ autonomi_version }}-x86_64-unknown-linux-musl.tar.gz"
tasks:
- name: stop the uploader service
- name: get list of safe users
ansible.builtin.shell: "getent passwd | grep '^safe[0-9]\\+:' | cut -d: -f1"
register: safe_users
changed_when: false

- name: stop all uploader services
systemd:
name: safe_uploader
name: "autonomi_uploader_{{ item | regex_replace('safe([0-9]+)', '\\1') }}"
state: stopped
loop: "{{ safe_users.stdout_lines }}"

# It is safer to make sure both of these are removed, because Ansible may not re-download and
# replace them if they already exist.
- name: remove existing safe binary
- name: remove existing autonomi binary
ansible.builtin.file:
path: /usr/local/bin/safe
path: /usr/local/bin/autonomi
state: absent

- name: remove existing safe archive
- name: remove existing autonomi archive
ansible.builtin.file:
path: /tmp/safe-latest-x86_64-unknown-linux-musl.tar.gz
path: /tmp/autonomi-latest-x86_64-unknown-linux-musl.tar.gz
state: absent

- name: download the new safe binary
- name: download the new autonomi binary
ansible.builtin.get_url:
url: "{{ safe_archive_url }}"
dest: /tmp/safe-latest-x86_64-unknown-linux-musl.tar.gz
url: "{{ autonomi_archive_url }}"
dest: /tmp/autonomi-latest-x86_64-unknown-linux-musl.tar.gz

- name: extract the new safe binary
- name: extract the new autonomi binary
ansible.builtin.unarchive:
src: /tmp/safe-latest-x86_64-unknown-linux-musl.tar.gz
src: /tmp/autonomi-latest-x86_64-unknown-linux-musl.tar.gz
dest: /usr/local/bin
remote_src: True

- name: start the uploader service
- name: start all uploader services
systemd:
name: safe_uploader
name: "autonomi_uploader_{{ item | regex_replace('safe([0-9]+)', '\\1') }}"
state: started
enabled: true
enabled: true
loop: "{{ safe_users.stdout_lines }}"
1 change: 0 additions & 1 deletion src/ansible/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ impl AnsibleInventoryType {
Self::BootstrapNodes,
Self::Nodes,
Self::PrivateNodes,
Self::EvmNodes,
]
.into_iter()
}
Expand Down
5 changes: 0 additions & 5 deletions src/ansible/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ pub enum AnsiblePlaybook {
StopTelegraf,
/// This playbook will stop the uploaders on each machine.
StopUploaders,
/// The upgrade faucet playbook will upgrade the faucet to the latest version.
///
/// Use in combination with `AnsibleInventoryType::Genesis`.
UpgradeFaucet,
/// The upgrade node manager playbook will upgrade the node manager to the latest version.
///
/// Use in combination with `AnsibleInventoryType::Genesis` or `AnsibleInventoryType::Nodes`.
Expand Down Expand Up @@ -191,7 +187,6 @@ impl AnsiblePlaybook {
AnsiblePlaybook::StopFaucet => "stop_faucet.yml".to_string(),
AnsiblePlaybook::StopTelegraf => "stop_telegraf.yml".to_string(),
AnsiblePlaybook::StopUploaders => "stop_uploaders.yml".to_string(),
AnsiblePlaybook::UpgradeFaucet => "upgrade_faucet.yml".to_string(),
AnsiblePlaybook::UpgradeNodeManager => "upgrade_node_manager.yml".to_string(),
AnsiblePlaybook::UpgradeNodes => "upgrade_nodes.yml".to_string(),
AnsiblePlaybook::UpgradeNodeTelegrafConfig => {
Expand Down
49 changes: 34 additions & 15 deletions src/ansible/provisioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ use evmlib::common::U256;
use log::{debug, error, trace};
use semver::Version;
use sn_service_management::NodeRegistry;
use std::{net::SocketAddr, path::PathBuf, time::Instant};
use std::{
net::SocketAddr,
path::PathBuf,
time::{Duration, Instant},
};
use walkdir::WalkDir;

use crate::ansible::extra_vars;
Expand Down Expand Up @@ -490,12 +494,37 @@ impl AnsibleProvisioner {
Ok(())
}

pub fn start_nodes(&self) -> Result<()> {
for node_inv_type in AnsibleInventoryType::iter_node_type() {
self.ansible_runner
.run_playbook(AnsiblePlaybook::StartNodes, node_inv_type, None)?;
pub fn start_nodes(
&self,
environment_name: &str,
interval: Duration,
custom_inventory: Option<Vec<VirtualMachine>>,
) -> Result<()> {
let mut extra_vars = ExtraVarsDocBuilder::default();
extra_vars.add_variable("interval", &interval.as_millis().to_string());

if let Some(custom_inventory) = custom_inventory {
println!("Running the start telegraf playbook with a custom inventory");
generate_custom_environment_inventory(
&custom_inventory,
environment_name,
&self.ansible_runner.working_directory_path.join("inventory"),
)?;
self.ansible_runner.run_playbook(
AnsiblePlaybook::StartNodes,
AnsibleInventoryType::Custom,
Some(extra_vars.build()),
)?;
return Ok(());
}

for node_inv_type in AnsibleInventoryType::iter_node_type() {
self.ansible_runner.run_playbook(
AnsiblePlaybook::StartNodes,
node_inv_type,
Some(extra_vars.build()),
)?;
}
Ok(())
}

Expand Down Expand Up @@ -665,16 +694,6 @@ impl AnsibleProvisioner {
println!("WARNING: the genesis node may not have been upgraded or restarted");
}
}
match self.ansible_runner.run_playbook(
AnsiblePlaybook::UpgradeFaucet,
AnsibleInventoryType::Genesis,
Some(options.get_ansible_vars()),
) {
Ok(()) => println!("The faucet was successfully upgraded"),
Err(_) => {
println!("WARNING: the faucet may not have been upgraded or restarted");
}
}
Ok(())
}

Expand Down
27 changes: 12 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,12 @@ pub struct UpgradeOptions {
pub ansible_verbose: bool,
pub custom_inventory: Option<Vec<VirtualMachine>>,
pub env_variables: Option<Vec<(String, String)>>,
pub faucet_version: Option<String>,
pub force_faucet: bool,
pub force_safenode: bool,
pub force: bool,
pub forks: usize,
pub interval: Duration,
pub name: String,
pub provider: CloudProvider,
pub safenode_version: Option<String>,
pub version: Option<String>,
}

impl UpgradeOptions {
Expand All @@ -355,16 +353,10 @@ impl UpgradeOptions {
if let Some(env_variables) = &self.env_variables {
extra_vars.add_env_variable_list("env_variables", env_variables.clone());
}
if self.force_faucet {
extra_vars.add_variable("force_faucet", &self.force_faucet.to_string());
if self.force {
extra_vars.add_variable("force", &self.force.to_string());
}
if let Some(version) = &self.faucet_version {
extra_vars.add_variable("faucet_version", version);
}
if self.force_safenode {
extra_vars.add_variable("force_safenode", &self.force_safenode.to_string());
}
if let Some(version) = &self.safenode_version {
if let Some(version) = &self.version {
extra_vars.add_variable("safenode_version", version);
}
extra_vars.build()
Expand Down Expand Up @@ -640,8 +632,13 @@ impl TestnetDeployer {
Ok(())
}

pub fn start(&self) -> Result<()> {
self.ansible_provisioner.start_nodes()?;
pub fn start(
&self,
interval: Duration,
custom_inventory: Option<Vec<VirtualMachine>>,
) -> Result<()> {
self.ansible_provisioner
.start_nodes(&self.environment_name, interval, custom_inventory)?;
Ok(())
}

Expand Down
Loading
Loading