[pve-devel] [PATCH manager] implement checks for ceph version & binaries
Alwin Antreich
a.antreich at proxmox.com
Wed Aug 23 19:02:00 CEST 2017
add version check to ceph init to require luminous or higher and
fix #1481: check existence of ceph binaries before use
Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
PVE/API2/Ceph.pm | 17 ++++++++++++++++-
PVE/CephTools.pm | 44 +++++++++++++++++++++++++++++++++++++++-----
2 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index c4d6ffcb..2a87cb67 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -233,6 +233,8 @@ __PACKAGE__->register_method ({
PVE::CephTools::setup_pve_symlinks();
+ PVE::CephTools::check_ceph_installed(undef, "ceph_osd");
+
my $bluestore = $param->{bluestore} // 0;
my $journal_dev;
@@ -827,7 +829,13 @@ __PACKAGE__->register_method ({
code => sub {
my ($param) = @_;
- PVE::CephTools::check_ceph_installed();
+ my $version = PVE::CephTools::get_local_version(1);
+
+ if (!$version || $version < 12) {
+ die "Ceph version luminous or higher is required\n";
+ } else {
+ PVE::CephTools::check_ceph_installed();
+ }
# simply load old config if it already exists
my $cfg = PVE::CephTools::parse_ceph_config();
@@ -982,6 +990,11 @@ __PACKAGE__->register_method ({
code => sub {
my ($param) = @_;
+ PVE::CephTools::check_ceph_installed(undef, "ceph_mon");
+
+ PVE::CephTools::check_ceph_installed(undef, "ceph_mgr")
+ if (!$param->{'exclude-manager'});
+
PVE::CephTools::check_ceph_inited();
PVE::CephTools::setup_pve_symlinks();
@@ -1220,6 +1233,8 @@ __PACKAGE__->register_method ({
code => sub {
my ($param) = @_;
+ PVE::CephTools::check_ceph_installed(undef, "ceph_mgr");
+
PVE::CephTools::check_ceph_inited();
my $rpcenv = PVE::RPCEnvironment::get();
diff --git a/PVE/CephTools.pm b/PVE/CephTools.pm
index 0c0d7c18..f13d2796 100644
--- a/PVE/CephTools.pm
+++ b/PVE/CephTools.pm
@@ -20,7 +20,12 @@ my $pve_ckeyring_path = "/etc/pve/priv/$ccname.client.admin.keyring";
my $ceph_bootstrap_osd_keyring = "/var/lib/ceph/bootstrap-osd/$ccname.keyring";
my $ceph_bootstrap_mds_keyring = "/var/lib/ceph/bootstrap-mds/$ccname.keyring";
-my $ceph_bin = "/usr/bin/ceph";
+my $ceph_service = {
+ ceph_bin => "/usr/bin/ceph",
+ ceph_mon => "/usr/bin/ceph-mon",
+ ceph_mgr => "/usr/bin/ceph-mgr",
+ ceph_osd => "/usr/bin/ceph-osd"
+};
my $config_hash = {
ccname => $ccname,
@@ -32,6 +37,23 @@ my $config_hash = {
long_rados_timeout => 60,
};
+sub get_local_version {
+ my ($noerr) = @_;
+
+ if (PVE::CephTools::check_ceph_installed($noerr)) {
+ my $ceph_version;
+ run_command([$ceph_service->{ceph_bin}, '--version'],
+ noerr => $noerr,
+ outfunc => sub { $ceph_version = shift; });
+ if ($ceph_version && $ceph_version =~ /^ceph.*\s((\d+)\.(\d+)\.(\d+))/) {
+ # return (version, major, minor, patch) : major;
+ return wantarray ? ($1, $2, $3, $4) : $2;
+ }
+ }
+
+ return undef;
+}
+
sub get_config {
my $key = shift;
@@ -60,11 +82,23 @@ sub purge_all_ceph_files {
}
sub check_ceph_installed {
- my ($noerr) = @_;
+ my ($noerr, $service) = @_;
- if (! -x $ceph_bin) {
- die "ceph binaries not installed\n" if !$noerr;
- return undef;
+ if (!defined($service)) {
+ if (! -x $ceph_service->{ceph_bin}) {
+ die "binary not installed: $ceph_service->{ceph_bin}\n" if !$noerr;
+ return undef;
+ }
+
+ } elsif (defined($service)) {
+ foreach my $key (keys %$ceph_service) {
+ next if $service ne $key;
+
+ if (! -x $ceph_service->{$key}){
+ die "binary not installed: $ceph_service->{$key}\n" if !$noerr;
+ return undef;
+ }
+ }
}
return 1;
--
2.11.0
More information about the pve-devel
mailing list