Skip to content

Commit

Permalink
Fix config_changed
Browse files Browse the repository at this point in the history
After a deploy it became obvious that config_changed
is needed on the subordinate machines or they won't
format any of their drives.  This also adds fstab
entries for any drives it formats and mounts so
they can survive a reboot.
  • Loading branch information
cholcombe973 committed Apr 6, 2017
1 parent 667c71d commit da2c79a
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 83 deletions.
90 changes: 50 additions & 40 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -6,6 +6,7 @@ authors = ["Chris Holcombe<chris.holcombe@canonical.com>"]
[dependencies]
chrono = { version = "0.3", features = ["rustc-serialize"] }
debian = "*"
fstab = "~0.3"
gluster = "~0.7"
init-daemon = "*"
ipnetwork = "~0.12"
Expand Down
1 change: 0 additions & 1 deletion hooks/brick-storage-attached

This file was deleted.

Binary file modified hooks/main
Binary file not shown.
28 changes: 27 additions & 1 deletion src/block.rs
Expand Up @@ -65,6 +65,8 @@ pub enum MediaType {
#[derive(Debug, Eq, PartialEq)]
pub enum FilesystemType {
Btrfs,
Ext2,
Ext3,
Ext4,
Xfs,
Zfs,
Expand All @@ -75,12 +77,36 @@ impl FilesystemType {
pub fn from_str(fs_type: &str) -> FilesystemType {
match fs_type {
"btrfs" => FilesystemType::Btrfs,
"ext2" => FilesystemType::Ext2,
"ext3" => FilesystemType::Ext3,
"ext4" => FilesystemType::Ext4,
"xfs" => FilesystemType::Xfs,
"zfs" => FilesystemType::Zfs,
_ => FilesystemType::Unknown,
}
}
pub fn to_str(&self) -> &str {
match self {
&FilesystemType::Btrfs => "btrfs",
&FilesystemType::Ext2 => "ext2",
&FilesystemType::Ext3 => "ext3",
&FilesystemType::Ext4 => "ext4",
&FilesystemType::Xfs => "xfs",
&FilesystemType::Zfs => "zfs",
&FilesystemType::Unknown => "unknown",
}
}
pub fn to_string(&self) -> String {
match self {
&FilesystemType::Btrfs => "btrfs".to_string(),
&FilesystemType::Ext2 => "ext2".to_string(),
&FilesystemType::Ext3 => "ext3".to_string(),
&FilesystemType::Ext4 => "ext4".to_string(),
&FilesystemType::Xfs => "xfs".to_string(),
&FilesystemType::Zfs => "zfs".to_string(),
&FilesystemType::Unknown => "unknown".to_string(),
}
}
}

impl MetadataProfile {
Expand Down Expand Up @@ -496,7 +522,7 @@ pub fn get_juju_bricks() -> Result<Vec<BrickDevice>, String> {
.unwrap_or("".to_string())
.lines()
.filter(|s| !s.is_empty())
.map(|s| juju::storage_get(s).unwrap())
.map(|s| juju::storage_get(s).unwrap().trim().to_string())
.collect();
log!(format!("List of juju storage brick devices: {:?}",
juju_config_brick_devices));
Expand Down
16 changes: 0 additions & 16 deletions src/hooks/brick_attached.rs

This file was deleted.

90 changes: 67 additions & 23 deletions src/hooks/config_changed.rs
Expand Up @@ -2,50 +2,94 @@ extern crate gluster;
extern crate juju;

use std::fs::File;
use std::path::{Path, PathBuf};
use std::path::Path;
use std::process::Command;

use super::super::{create_sysctl, ephemeral_unmount, device_initialized, get_config_value,
get_glusterfs_version, initialize_storage, is_mounted};
use super::super::{create_sysctl, ephemeral_unmount, finish_initialization, get_glusterfs_version,
initialize_storage};
use super::super::apt;
use super::super::block;
use super::super::upgrade;

pub fn config_changed() -> Result<(), String> {
// If either of these fail we fail the hook
check_for_new_devices()?;
check_for_upgrade()?;

// If this fails don't fail the hook
if let Err(err) = check_for_new_devices() {
log!(format!("Checking for new devices failed with error: {}", err),
Error);
}
if let Err(err) = check_for_sysctl() {
log!(format!("Setting sysctl's failed with error: {}", err),
Error);
}
// If fails we fail the hook
check_for_upgrade()?;
return Ok(());
}

fn check_for_new_devices() -> Result<(), String> {
log!("Checking for new devices", Info);
let config = juju::Config::new().map_err(|e| e.to_string())?;
if config.changed("brick_devices").map_err(|e| e.to_string())? {
// Get the changed list of brick devices and initialize each one
let mut brick_devices: Vec<block::BrickDevice> = Vec::new();
log!("Checking for ephemeral unmount");
ephemeral_unmount()?;
//if config.changed("brick_devices").map_err(|e| e.to_string())? {
let mut brick_devices: Vec<block::BrickDevice> = Vec::new();
// Get user configured storage devices
let manual_brick_devices = block::get_manual_bricks()?;
brick_devices.extend(manual_brick_devices);

log!("Checking for ephemeral unmount");
ephemeral_unmount()?;
// Get the juju storage block devices
let juju_config_brick_devices = block::get_juju_bricks()?;
brick_devices.extend(juju_config_brick_devices);

// Get user configured storage devices
let manual_brick_devices = block::get_manual_bricks()?;
brick_devices.extend(manual_brick_devices);
log!(format!("storage devices: {:?}", brick_devices));

// Get the juju storage block devices
let juju_config_brick_devices = block::get_juju_bricks()?;
brick_devices.extend(juju_config_brick_devices);

log!(format!("storage devices: {:?}", brick_devices));
} else {
log!("No new devices found");
let mut format_handles: Vec<block::AsyncInit> = Vec::new();
let mut brick_paths: Vec<String> = Vec::new();
// Format all drives in parallel
for device in &mut brick_devices {
if !device.initialized {
log!(format!("Calling initialize_storage for {:?}", device.dev_path));
// Spawn all format commands in the background
format_handles.push(initialize_storage(device.clone())?);
} else {
// The device is already initialized, lets add it to our usable paths list
log!(format!("{:?} is already initialized", device.dev_path));
brick_paths.push(device.mount_path.clone());
}
}
// Wait for all children to finish formatting their drives
for handle in format_handles {
let output_result = handle.format_child.wait_with_output();
match output_result {
Ok(output) => {
match block::process_output(output) {
Ok(_) => {
// success
// 1. Run any post setup commands if needed
finish_initialization(&handle.device.dev_path).map_err(|e| e.to_string())?;
brick_paths.push(handle.device.mount_path.clone());
}
Err(e) => {
// Failed
log!(format!("Device {:?} formatting failed with error: {}. Skipping",
&handle.device.dev_path,
e),
Error);
}
}
}
Err(e) => {
//Failed
log!(format!("Device {:?} formatting failed with error: {}. Skipping",
&handle.device.dev_path,
e),
Error);
}
}
}
log!(format!("Usable brick paths: {:?}", brick_paths));
//} else {
// log!("No new devices found");
//}
Ok(())
}

Expand Down
1 change: 0 additions & 1 deletion src/hooks/mod.rs
@@ -1,4 +1,3 @@
pub mod brick_attached;
pub mod brick_detached;
pub mod config_changed;
pub mod fuse_relation_joined;
Expand Down
1 change: 0 additions & 1 deletion src/hooks/server_changed.rs
Expand Up @@ -360,7 +360,6 @@ fn get_brick_list(peers: &Vec<Peer>,
Error);
}
}

}
log!(format!("Usable brick paths: {:?}", brick_paths));

Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Expand Up @@ -321,6 +321,7 @@ fn ephemeral_unmount() -> Result<(), String> {
}
// Remove the entry from the fstab if it's set
let fstab = fstab::FsTab::new(&Path::new("/etc/fstab"));
log!("Removing ephemeral mount from fstab");
fstab.remove_entry(&mountpoint).map_err(|e| e.to_string())?;

if is_mounted(&mountpoint)? {
Expand Down

0 comments on commit da2c79a

Please sign in to comment.